django - URL redirection issue using PK -


hi guys have primary key issue following error : django.urls.exceptions.noreversematch: reverse 'addteam' not found. 'addteam' not valid view function or pattern name.

my app simple : user create project arrive page in detail page button in order invite user using mails ... thing error after creating project

here code :

urls.py:

from django.conf.urls import url website import views  app_name = 'website' urlpatterns = [     url(r'^candidateindex/$', views.candidateindex.as_view(), name='candidate_index'),     url(r'^hrcreate/$', views.projectcreate.as_view(), name='hr_create'),     url(r'^project/(?p<pk>[0-9]+)/$',views.projectdetailview.as_view(), name='projectdetails'),     url(r'^project/(?p<pk>[0-9]+)/invite/$',views.create_invite, name='addteam'), ] 

views.py:

from django.shortcuts import render django.views import generic django.views.generic import templateview django.views.generic.edit import createview, updateview, deleteview .forms import inviteform invitations.models import invitation .models import project django.core.urlresolvers import reverse  # create views here.  class homepage(templateview):     template_name= 'index.html'  class candidateindex(templateview):     template_name= 'candidateindex.html'  class hrindex(templateview):     template_name= 'hrindex.html'  class projectdetailview(generic.detailview):     model = project     template_name = 'project_details.html'  class projectcreate(createview):     model = project     fields = ['project_name']     template_name = 'project_form.html'   def create_invite(request, pk):     if request.method == "post":         invite_form = inviteform(data=request.post)         if invite_form.is_valid():             email1 = invite_form.cleaned_data['email1']             email2 = invite_form.cleaned_data['email2']             email3 = invite_form.cleaned_data['email3']             email4 = invite_form.cleaned_data['email4']             email5 = invite_form.cleaned_data['email5']             in invite_form.cleaned_data:                 invite = invitation.create(i)                 invite.send_invitation(request)             print("the mail went")             #return reverse('website:projectdetails', kwargs = {'pk' : self.pk} )         else:             print("your form not valid")     else:         invite_form = inviteform()     return render(request, 'team_invite.html', {'invite_form': invite_form}) 

models.py:

from django.db import models django.core.urlresolvers import reverse  class project(models.model):     project_name = models.charfield(max_length=150)     created_at = models.datetimefield(auto_now_add=true)      def get_absolute_url(self):         return reverse('website:projectdetails', kwargs = {'pk' : self.pk})      def __str__(self):         return self.project_name   class team(models.model):     project = models.foreignkey(project)     team_name = models.charfield(max_length=150)      def __str__(self):         return self.team_name 

project_details.html:

{% extends 'base.html' %} {% block body %} <div class="container">   <div class="jumbotron">     <h2>welcome project {{project.project_name}} detail page</h2>   </div>   <div class="invite-team">       <a href="{% url 'website:addteam'%}">gogo</a>   </div> </div>     {% endblock%} 

the error : in template /users/raphaelbendenoun/documents/softscores_project_final/templates/base.html, error @ line 8 reverse 'addteam' not found. 'addteam' not valid view function or pattern name.

--> line 8 bootsrap link ...

the line below indicates view accepting primary key project model.

url(r'^project/(?p<pk>[0-9]+)/invite/$',views.create_invite, name='addteam'), 

however view below not indicated using project model in it.

def create_invite(request, pk): 

so change

 def create_invite(request, pk):  

to

 def create_invite(request): 

and

url(r'^project/(?p<pk>[0-9]+)/invite/$',views.create_invite, name='addteam') 

to

url(r'^project/invite/$',views.create_invite, name='addteam')  

hopefully template should work.

if need pass primary key view, in template need do

<a href="{% url 'website:addteam' pk_key_value %}">gogo</a> 

where pk_key_value should variable primary key of model object.

below link give more clarity. https://docs.djangoproject.com/en/1.11/topics/http/urls/

also sending emails refer https://docs.djangoproject.com/en/1.11/topics/email/

you dont seem have 'imported django.core.mail'


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -