Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

anyi.lloyd@gmail.com
Am new to Django, please i need help here. Am trying to add a subject into a particular id using generic CreatView, i keeping getting errors
Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

models.py

from django.db import models
from datetime import date
from django.core.urlresolvers import reverse
from django.shortcuts import redirect


class Profile(models.Model):
firstName = models.CharField(max_length=30)
middleName = models.CharField(max_length=30)
lastName = models.CharField(max_length=30)
dob = models.DateField(blank=True, null=True)
stud_id = models.CharField(max_length=5000)
gender = models.CharField(max_length=10)
parentsName =models.CharField(max_length=30)
address = models.CharField(max_length=250)
lga = models.CharField(max_length=250)
Religion = models.CharField(max_length=50)
email = models.EmailField(max_length=70, null=True, blank=True, unique=True)
phone = models.CharField(max_length=11, unique=True)
photo = models.FileField()
Comment = models.CharField(max_length=250)

def get_absolute_url(self):
return reverse('student:detail', kwargs={'pk': self.pk})

def __str__(self):
return self.firstName

class Course(models.Model):
profile = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True)
subject = models.CharField(max_length=20)
score = models.CharField(max_length=20)
grade = models.CharField(max_length=20)

def get_absolute_url(self,):
return reverse('student:detail', kwargs={'pk': self.pk})

views.py
from django.views import generic
from django.views.generic import View
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy, reverse
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login
from .models import Profile, Course
from .forms import UserForm



#Index view
class IndexView(generic.ListView):
template_name = 'student/index.html'
context_object_name = 'all_profile'

def get_queryset(self):
return Profile.objects.all()

#Detail view
class DetailView(generic.DetailView):
model = Profile
template_name = 'student/detail.html'

#Add student section
class ProfileCreate(generic.CreateView):
model = Profile
fields = ['firstName', 'middleName', 'lastName', 'dob', 'gender', 'parentsName', 'address',
'lga', 'Religion', 'email', 'phone', 'photo']

#Add Subject section
class CourseCreate(CreateView):
model = Course
fields = ['subject', 'score', 'grade']


def get_form_kwargs(self):
kwargs = super(CourseCreate, self).get_form_kwargs()
kwargs['instance'] = Course(pk=self.kwargs['pk'])
return kwargs

urls.py

urlpatterns = [
#index url
url(r'^$', views.IndexView.as_view(), name='index'),

url(r'^signup/$', views.UserFormView.as_view(), name='signup'),
#details
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
#profile/add
url(r'^profile/add/$', views.ProfileCreate.as_view(), name='profile-add'),
#course/add
url(r'^(?P<pk>[0-9]+)/course_form/$', views.CourseCreate.as_view(), name='course_form'),
#profile/pk for update
url(r'^profile/(?P<pk>[0-9]+)/$', views.ProfileUpdate.as_view(), name='profile-update'),
#profile/pk for deleting
url(r'^profile/(?P<pk>[0-9]+)/delete/$', views.ProfileDelete.as_view(), name='profile-delete'),
]


template
{% extends 'student/base.html' %}
{% block title %}{% endblock %}

{% block body %}

<div class="container subject-container">
<div class="row">
<!-- profile photo-->
<div class="col-sm-4 col-md-3">
<div class="panel panel-primary">
<div class="panel-heading">
<h1 class="panel-title">{{profile.lastName}} {{profile.firstName}}</h1>
</div>
<div class="panel-body">
<a href="{% url 'student:detail' profile.id %}">
{% if profile.photo %}
<img src="{{ profile.photo.url }}" class="img-thumbnail" width="250px" hieght="100px">
{% else %}
<p class="small">No image to display</p>
{% endif %}
</a>
</div>
</div>

</div>

<!-- Subject Add-->
<ul class="nav nav-pills" style="margin-bottom: 10px;">
<li role="presentation"><a href="{% url 'student:detail' profile.id %}">View All</a></li>
<li role="presentation" class="active"><a href="{% url 'student:course_form' profile.id %}">Add New Song</a></li>
</ul>
<div class="col-sm-12 col-md-7">
<div class="panel panel-success">
<div class="panel-heading">
<h1 class="panel-title">Add Subject</h1>
</div>
<div class="panel-body">
<h3>Add Subject</h3>
{% if error_message %}
<p><strong>{{ error_message }}</strong></p>
{% endif %}
<form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="hidden" name="profile" value="{{ profile }}">
{% include 'student/form-profile-temp.html' %}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>

</div>
</div>

</div>

</div>
</div>
{% endblock %}

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/f25ae29c-0479-432d-94d3-675ed4753db2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

Andy-3
If you actually are inside the profile create view, the profile probably does not have an id yet and thats why the url lookup is failing. The ID will be created on first save of the object.

Am Dienstag, 6. März 2018 00:11:53 UTC+1 schrieb anyi.lloyd:
Am new to Django, please i need help here. Am trying to add a subject into a particular id using generic CreatView, i keeping getting errors
Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

models.py

from django.db import models
from datetime import date
from django.core.urlresolvers import reverse
from django.shortcuts import redirect


class Profile(models.Model):
firstName = models.CharField(max_length=30)
middleName = models.CharField(max_length=30)
lastName = models.CharField(max_length=30)
dob = models.DateField(blank=True, null=True)
stud_id = models.CharField(max_length=5000)
gender = models.CharField(max_length=10)
parentsName =models.CharField(max_length=30)
address = models.CharField(max_length=250)
lga = models.CharField(max_length=250)
Religion = models.CharField(max_length=50)
email = models.EmailField(max_length=70, null=True, blank=True, unique=True)
phone = models.CharField(max_length=11, unique=True)
photo = models.FileField()
Comment = models.CharField(max_length=250)

def get_absolute_url(self):
return reverse('student:detail', kwargs={'pk': self.pk})

def __str__(self):
return self.firstName

class Course(models.Model):
profile = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True)
subject = models.CharField(max_length=20)
score = models.CharField(max_length=20)
grade = models.CharField(max_length=20)

def get_absolute_url(self,):
return reverse('student:detail', kwargs={'pk': self.pk})

views.py
from django.views import generic
from django.views.generic import View
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy, reverse
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login
from .models import Profile, Course
from .forms import UserForm



#Index view
class IndexView(generic.ListView):
template_name = 'student/index.html'
context_object_name = 'all_profile'

def get_queryset(self):
return Profile.objects.all()

#Detail view
class DetailView(generic.DetailView):
model = Profile
template_name = 'student/detail.html'

#Add student section
class ProfileCreate(generic.CreateView):
model = Profile
fields = ['firstName', 'middleName', 'lastName', 'dob', 'gender', 'parentsName', 'address',
'lga', 'Religion', 'email', 'phone', 'photo']

#Add Subject section
class CourseCreate(CreateView):
model = Course
fields = ['subject', 'score', 'grade']


def get_form_kwargs(self):
kwargs = super(CourseCreate, self).get_form_kwargs()
kwargs['instance'] = Course(pk=self.kwargs['pk'])
return kwargs

urls.py

urlpatterns = [
#index url
url(r'^$', views.IndexView.as_view(), name='index'),

url(r'^signup/$', views.UserFormView.as_view(), name='signup'),
#details
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
#profile/add
url(r'^profile/add/$', views.ProfileCreate.as_view(), name='profile-add'),
#course/add
url(r'^(?P<pk>[0-9]+)/course_form/$', views.CourseCreate.as_view(), name='course_form'),
#profile/pk for update
url(r'^profile/(?P<pk>[0-9]+)/$', views.ProfileUpdate.as_view(), name='profile-update'),
#profile/pk for deleting
url(r'^profile/(?P<pk>[0-9]+)/delete/$', views.ProfileDelete.as_view(), name='profile-delete'),
]


template
{% extends 'student/base.html' %}
{% block title %}{% endblock %}

{% block body %}

<div class="container subject-container">
<div class="row">
<!-- profile photo-->
<div class="col-sm-4 col-md-3">
<div class="panel panel-primary">
<div class="panel-heading">
<h1 class="panel-title">{{profile.lastName}} {{profile.firstName}}</h1>
</div>
<div class="panel-body">
<a href="{% url 'student:detail' <a href="http://profile.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;">profile.id %}">
{% if profile.photo %}
<img src="{{ profile.photo.url }}" class="img-thumbnail" width="250px" hieght="100px">
{% else %}
<p class="small">No image to display</p>
{% endif %}
</a>
</div>
</div>

</div>

<!-- Subject Add-->
<ul class="nav nav-pills" style="margin-bottom: 10px;">
<li role="presentation"><a href="{% url 'student:detail' <a href="http://profile.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;">profile.id %}">View All</a></li>
<li role="presentation" class="active"><a href="{% url 'student:course_form' <a href="http://profile.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;">profile.id %}">Add New Song</a></li>
</ul>
<div class="col-sm-12 col-md-7">
<div class="panel panel-success">
<div class="panel-heading">
<h1 class="panel-title">Add Subject</h1>
</div>
<div class="panel-body">
<h3>Add Subject</h3>
{% if error_message %}
<p><strong>{{ error_message }}</strong></p>
{% endif %}
<form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="hidden" name="profile" value="{{ profile }}">
{% include 'student/form-profile-temp.html' %}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>

</div>
</div>

</div>

</div>
</div>
{% endblock %}

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

anyi.lloyd@gmail.com
In reply to this post by anyi.lloyd@gmail.com
The profile already have an id. Just wanted to add to an existing profile in the db with generic view.


----- Reply message -----
From: "Andy" <[hidden email]>
To: "Django users" <[hidden email]>
Subject: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']
Date: Wed, Mar 7, 2018 11:08

If you actually are inside the profile create view, the profile probably does not have an id yet and thats why the url lookup is failing. The ID will be created on first save of the object.

Am Dienstag, 6. März 2018 00:11:53 UTC+1 schrieb anyi.lloyd:
Am new to Django, please i need help here. Am trying to add a subject into a particular id using generic CreatView, i keeping getting errors
Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

models.py

from django.db import models
from datetime import date
from django.core.urlresolvers import reverse
from django.shortcuts import redirect


class Profile(models.Model):
firstName = models.CharField(max_length=30)
middleName = models.CharField(max_length=30)
lastName = models.CharField(max_length=30)
dob = models.DateField(blank=True, null=True)
stud_id = models.CharField(max_length=5000)
gender = models.CharField(max_length=10)
parentsName =models.CharField(max_length=30)
address = models.CharField(max_length=250)
lga = models.CharField(max_length=250)
Religion = models.CharField(max_length=50)
email = models.EmailField(max_length=70, null=True, blank=True, unique=True)
phone = models.CharField(max_length=11, unique=True)
photo = models.FileField()
Comment = models.CharField(max_length=250)

def get_absolute_url(self):
return reverse('student:detail', kwargs={'pk': self.pk})

def __str__(self):
return self.firstName

class Course(models.Model):
profile = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True)
subject = models.CharField(max_length=20)
score = models.CharField(max_length=20)
grade = models.CharField(max_length=20)

def get_absolute_url(self,):
return reverse('student:detail', kwargs={'pk': self.pk})

views.py
from django.views import generic
from django.views.generic import View
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy, reverse
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login
from .models import Profile, Course
from .forms import UserForm



#Index view
class IndexView(generic.ListView):
template_name = 'student/index.html'
context_object_name = 'all_profile'

def get_queryset(self):
return Profile.objects.all()

#Detail view
class DetailView(generic.DetailView):
model = Profile
template_name = 'student/detail.html'

#Add student section
class ProfileCreate(generic.CreateView):
model = Profile
fields = ['firstName', 'middleName', 'lastName', 'dob', 'gender', 'parentsName', 'address',
'lga', 'Religion', 'email', 'phone', 'photo']

#Add Subject section
class CourseCreate(CreateView):
model = Course
fields = ['subject', 'score', 'grade']


def get_form_kwargs(self):
kwargs = super(CourseCreate, self).get_form_kwargs()
kwargs['instance'] = Course(pk=self.kwargs['pk'])
return kwargs

urls.py

urlpatterns = [
#index url
url(r'^$', views.IndexView.as_view(), name='index'),

url(r'^signup/$', views.UserFormView.as_view(), name='signup'),
#details
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
#profile/add
url(r'^profile/add/$', views.ProfileCreate.as_view(), name='profile-add'),
#course/add
url(r'^(?P<pk>[0-9]+)/course_form/$', views.CourseCreate.as_view(), name='course_form'),
#profile/pk for update
url(r'^profile/(?P<pk>[0-9]+)/$', views.ProfileUpdate.as_view(), name='profile-update'),
#profile/pk for deleting
url(r'^profile/(?P<pk>[0-9]+)/delete/$', views.ProfileDelete.as_view(), name='profile-delete'),
]


template
{% extends 'student/base.html' %}
{% block title %}{% endblock %}

{% block body %}

<div class="container subject-container">
<div class="row">
<!-- profile photo-->
<div class="col-sm-4 col-md-3">
<div class="panel panel-primary">
<div class="panel-heading">
<h1 class="panel-title">{{profile.lastName}} {{profile.firstName}}</h1>
</div>
<div class="panel-body">
<a href="{% url 'student:detail' <a href="http://profile.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;">profile.id %}">
{% if profile.photo %}
<img src="{{ profile.photo.url }}" class="img-thumbnail" width="250px" hieght="100px">
{% else %}
<p class="small">No image to display</p>
{% endif %}
</a>
</div>
</div>

</div>

<!-- Subject Add-->
<ul class="nav nav-pills" style="margin-bottom: 10px;">
<li role="presentation"><a href="{% url 'student:detail' <a href="http://profile.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;">profile.id %}">View All</a></li>
<li role="presentation" class="active"><a href="{% url 'student:course_form' <a href="http://profile.id" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;">profile.id %}">Add New Song</a></li>
</ul>
<div class="col-sm-12 col-md-7">
<div class="panel panel-success">
<div class="panel-heading">
<h1 class="panel-title">Add Subject</h1>
</div>
<div class="panel-body">
<h3>Add Subject</h3>
{% if error_message %}
<p><strong>{{ error_message }}</strong></p>
{% endif %}
<form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="hidden" name="profile" value="{{ profile }}">
{% include 'student/form-profile-temp.html' %}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>

</div>
</div>

</div>

</div>
</div>
{% endblock %}

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

Andy Grabow
Well, is it actually named profile inside the view? Rather than the default original? Check if the name is right and your profile is named profile in the template. 

[hidden email] <[hidden email]> schrieb am Mi. 7. März 2018 um 20:15:
The profile already have an id. Just wanted to add to an existing profile in the db with generic view.


----- Reply message -----
From: "Andy" <[hidden email]>
To: "Django users" <[hidden email]>
Subject: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']
Date: Wed, Mar 7, 2018 11:08

If you actually are inside the profile create view, the profile probably does not have an id yet and thats why the url lookup is failing. The ID will be created on first save of the object.

Am Dienstag, 6. März 2018 00:11:53 UTC+1 schrieb anyi.lloyd:
Am new to Django, please i need help here. Am trying to add a subject into a particular id using generic CreatView, i keeping getting errors
Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

models.py

from django.db import models
from datetime import date
from django.core.urlresolvers import reverse
from django.shortcuts import redirect


class Profile(models.Model):
firstName = models.CharField(max_length=30)
middleName = models.CharField(max_length=30)
lastName = models.CharField(max_length=30)
dob = models.DateField(blank=True, null=True)
stud_id = models.CharField(max_length=5000)
gender = models.CharField(max_length=10)
parentsName =models.CharField(max_length=30)
address = models.CharField(max_length=250)
lga = models.CharField(max_length=250)
Religion = models.CharField(max_length=50)
email = models.EmailField(max_length=70, null=True, blank=True, unique=True)
phone = models.CharField(max_length=11, unique=True)
photo = models.FileField()
Comment = models.CharField(max_length=250)

def get_absolute_url(self):
return reverse('student:detail', kwargs={'pk': self.pk})

def __str__(self):
return self.firstName

class Course(models.Model):
profile = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True)
subject = models.CharField(max_length=20)
score = models.CharField(max_length=20)
grade = models.CharField(max_length=20)

def get_absolute_url(self,):
return reverse('student:detail', kwargs={'pk': self.pk})

views.py
from django.views import generic
from django.views.generic import View
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy, reverse
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login
from .models import Profile, Course
from .forms import UserForm



#Index view
class IndexView(generic.ListView):
template_name = 'student/index.html'
context_object_name = 'all_profile'

def get_queryset(self):
return Profile.objects.all()

#Detail view
class DetailView(generic.DetailView):
model = Profile
template_name = 'student/detail.html'

#Add student section
class ProfileCreate(generic.CreateView):
model = Profile
fields = ['firstName', 'middleName', 'lastName', 'dob', 'gender', 'parentsName', 'address',
'lga', 'Religion', 'email', 'phone', 'photo']

#Add Subject section
class CourseCreate(CreateView):
model = Course
fields = ['subject', 'score', 'grade']


def get_form_kwargs(self):
kwargs = super(CourseCreate, self).get_form_kwargs()
kwargs['instance'] = Course(pk=self.kwargs['pk'])
return kwargs

urls.py

urlpatterns = [
#index url
url(r'^$', views.IndexView.as_view(), name='index'),

url(r'^signup/$', views.UserFormView.as_view(), name='signup'),
#details
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
#profile/add
url(r'^profile/add/$', views.ProfileCreate.as_view(), name='profile-add'),
#course/add
url(r'^(?P<pk>[0-9]+)/course_form/$', views.CourseCreate.as_view(), name='course_form'),
#profile/pk for update
url(r'^profile/(?P<pk>[0-9]+)/$', views.ProfileUpdate.as_view(), name='profile-update'),
#profile/pk for deleting
url(r'^profile/(?P<pk>[0-9]+)/delete/$', views.ProfileDelete.as_view(), name='profile-delete'),
]


template
{% extends 'student/base.html' %}
{% block title %}{% endblock %}

{% block body %}

<div class="container subject-container">
<div class="row">
<!-- profile photo-->
<div class="col-sm-4 col-md-3">
<div class="panel panel-primary">
<div class="panel-heading">
<h1 class="panel-title">{{profile.lastName}} {{profile.firstName}}</h1>
</div>
<div class="panel-body">
<a href="{% url 'student:detail' profile.id %}">
{% if profile.photo %}
<img src="{{ profile.photo.url }}" class="img-thumbnail" width="250px" hieght="100px">
{% else %}
<p class="small">No image to display</p>
{% endif %}
</a>
</div>
</div>

</div>

<!-- Subject Add-->
<ul class="nav nav-pills" style="margin-bottom: 10px;">
<li role="presentation"><a href="{% url 'student:detail' profile.id %}">View All</a></li>
<li role="presentation" class="active"><a href="{% url 'student:course_form' profile.id %}">Add New Song</a></li>
</ul>
<div class="col-sm-12 col-md-7">
<div class="panel panel-success">
<div class="panel-heading">
<h1 class="panel-title">Add Subject</h1>
</div>
<div class="panel-body">
<h3>Add Subject</h3>
{% if error_message %}
<p><strong>{{ error_message }}</strong></p>
{% endif %}
<form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="hidden" name="profile" value="{{ profile }}">
{% include 'student/form-profile-temp.html' %}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>

</div>
</div>

</div>

</div>
</div>
{% endblock %}

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.
--

Mit besten Grüßen
Andy

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B8CBRiZjbxssLZt8J%3Dst7i%3DM5b%3D8nhFasJMqUp_wYAEaWm_JA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

anyi.lloyd@gmail.com
In reply to this post by anyi.lloyd@gmail.com
Yes it is named profile.

----- Reply message -----
From: "Andy Grabow" <[hidden email]>
To: <[hidden email]>
Subject: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']
Date: Thu, Mar 8, 2018 05:18

Well, is it actually named profile inside the view? Rather than the default original? Check if the name is right and your profile is named profile in the template. 

[hidden email] <[hidden email]> schrieb am Mi. 7. März 2018 um 20:15:
The profile already have an id. Just wanted to add to an existing profile in the db with generic view.


----- Reply message -----
From: "Andy" <[hidden email]>
To: "Django users" <[hidden email]>
Subject: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']
Date: Wed, Mar 7, 2018 11:08

If you actually are inside the profile create view, the profile probably does not have an id yet and thats why the url lookup is failing. The ID will be created on first save of the object.

Am Dienstag, 6. März 2018 00:11:53 UTC+1 schrieb anyi.lloyd:
Am new to Django, please i need help here. Am trying to add a subject into a particular id using generic CreatView, i keeping getting errors
Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

models.py

from django.db import models
from datetime import date
from django.core.urlresolvers import reverse
from django.shortcuts import redirect


class Profile(models.Model):
firstName = models.CharField(max_length=30)
middleName = models.CharField(max_length=30)
lastName = models.CharField(max_length=30)
dob = models.DateField(blank=True, null=True)
stud_id = models.CharField(max_length=5000)
gender = models.CharField(max_length=10)
parentsName =models.CharField(max_length=30)
address = models.CharField(max_length=250)
lga = models.CharField(max_length=250)
Religion = models.CharField(max_length=50)
email = models.EmailField(max_length=70, null=True, blank=True, unique=True)
phone = models.CharField(max_length=11, unique=True)
photo = models.FileField()
Comment = models.CharField(max_length=250)

def get_absolute_url(self):
return reverse('student:detail', kwargs={'pk': self.pk})

def __str__(self):
return self.firstName

class Course(models.Model):
profile = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True)
subject = models.CharField(max_length=20)
score = models.CharField(max_length=20)
grade = models.CharField(max_length=20)

def get_absolute_url(self,):
return reverse('student:detail', kwargs={'pk': self.pk})

views.py
from django.views import generic
from django.views.generic import View
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy, reverse
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login
from .models import Profile, Course
from .forms import UserForm



#Index view
class IndexView(generic.ListView):
template_name = 'student/index.html'
context_object_name = 'all_profile'

def get_queryset(self):
return Profile.objects.all()

#Detail view
class DetailView(generic.DetailView):
model = Profile
template_name = 'student/detail.html'

#Add student section
class ProfileCreate(generic.CreateView):
model = Profile
fields = ['firstName', 'middleName', 'lastName', 'dob', 'gender', 'parentsName', 'address',
'lga', 'Religion', 'email', 'phone', 'photo']

#Add Subject section
class CourseCreate(CreateView):
model = Course
fields = ['subject', 'score', 'grade']


def get_form_kwargs(self):
kwargs = super(CourseCreate, self).get_form_kwargs()
kwargs['instance'] = Course(pk=self.kwargs['pk'])
return kwargs

urls.py

urlpatterns = [
#index url
url(r'^$', views.IndexView.as_view(), name='index'),

url(r'^signup/$', views.UserFormView.as_view(), name='signup'),
#details
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
#profile/add
url(r'^profile/add/$', views.ProfileCreate.as_view(), name='profile-add'),
#course/add
url(r'^(?P<pk>[0-9]+)/course_form/$', views.CourseCreate.as_view(), name='course_form'),
#profile/pk for update
url(r'^profile/(?P<pk>[0-9]+)/$', views.ProfileUpdate.as_view(), name='profile-update'),
#profile/pk for deleting
url(r'^profile/(?P<pk>[0-9]+)/delete/$', views.ProfileDelete.as_view(), name='profile-delete'),
]


template
{% extends 'student/base.html' %}
{% block title %}{% endblock %}

{% block body %}

<div class="container subject-container">
<div class="row">
<!-- profile photo-->
<div class="col-sm-4 col-md-3">
<div class="panel panel-primary">
<div class="panel-heading">
<h1 class="panel-title">{{profile.lastName}} {{profile.firstName}}</h1>
</div>
<div class="panel-body">
<a href="{% url 'student:detail' profile.id %}">
{% if profile.photo %}
<img src="{{ profile.photo.url }}" class="img-thumbnail" width="250px" hieght="100px">
{% else %}
<p class="small">No image to display</p>
{% endif %}
</a>
</div>
</div>

</div>

<!-- Subject Add-->
<ul class="nav nav-pills" style="margin-bottom: 10px;">
<li role="presentation"><a href="{% url 'student:detail' profile.id %}">View All</a></li>
<li role="presentation" class="active"><a href="{% url 'student:course_form' profile.id %}">Add New Song</a></li>
</ul>
<div class="col-sm-12 col-md-7">
<div class="panel panel-success">
<div class="panel-heading">
<h1 class="panel-title">Add Subject</h1>
</div>
<div class="panel-body">
<h3>Add Subject</h3>
{% if error_message %}
<p><strong>{{ error_message }}</strong></p>
{% endif %}
<form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="hidden" name="profile" value="{{ profile }}">
{% include 'student/form-profile-temp.html' %}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>

</div>
</div>

</div>

</div>
</div>
{% endblock %}

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.
--

Mit besten Grüßen
Andy

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CA%2B8CBRiZjbxssLZt8J%3Dst7i%3DM5b%3D8nhFasJMqUp_wYAEaWm_JA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5aa18551.46a4df0a.23d10.bcde%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

Andy-3
which one of your calls to detail are failing?
<a href="{% url 'student:detail' profile.id %}">
or
reverse('student:detail', kwargs={'pk': self.pk})
?

if its the second one, try with args=[self.pk]

Am Donnerstag, 8. März 2018 19:48:44 UTC+1 schrieb anyi.lloyd:
Yes it is named profile.

----- Reply message -----
From: "Andy Grabow" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">an...@...>
To: <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@...>
Subject: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']
Date: Thu, Mar 8, 2018 05:18

Well, is it actually named profile inside the view? Rather than the default original? Check if the name is right and your profile is named profile in the template. 

<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">anyi....@... <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">anyi....@...> schrieb am Mi. 7. März 2018 um 20:15:
The profile already have an id. Just wanted to add to an existing profile in the db with generic view.


----- Reply message -----
From: "Andy" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">kaku...@...>
To: "Django users" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@...>
Subject: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']
Date: Wed, Mar 7, 2018 11:08

If you actually are inside the profile create view, the profile probably does not have an id yet and thats why the url lookup is failing. The ID will be created on first save of the object.

Am Dienstag, 6. März 2018 00:11:53 UTC+1 schrieb anyi.lloyd:
Am new to Django, please i need help here. Am trying to add a subject into a particular id using generic CreatView, i keeping getting errors
Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

models.py

from django.db import models
from datetime import date
from django.core.urlresolvers import reverse
from django.shortcuts import redirect


class Profile(models.Model):
firstName = models.CharField(max_length=30)
middleName = models.CharField(max_length=30)
lastName = models.CharField(max_length=30)
dob = models.DateField(blank=True, null=True)
stud_id = models.CharField(max_length=5000)
gender = models.CharField(max_length=10)
parentsName =models.CharField(max_length=30)
address = models.CharField(max_length=250)
lga = models.CharField(max_length=250)
Religion = models.CharField(max_length=50)
email = models.EmailField(max_length=70, null=True, blank=True, unique=True)
phone = models.CharField(max_length=11, unique=True)
photo = models.FileField()
Comment = models.CharField(max_length=250)

def get_absolute_url(self):
return reverse('student:detail', kwargs={'pk': self.pk})

def __str__(self):
return self.firstName

class Course(models.Model):
profile = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True)
subject = models.CharField(max_length=20)
score = models.CharField(max_length=20)
grade = models.CharField(max_length=20)

def get_absolute_url(self,):
return reverse('student:detail', kwargs={'pk': self.pk})

views.py
from django.views import generic
from django.views.generic import View
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy, reverse
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login
from .models import Profile, Course
from .forms import UserForm



#Index view
class IndexView(generic.ListView):
template_name = 'student/index.html'
context_object_name = 'all_profile'

def get_queryset(self):
return Profile.objects.all()

#Detail view
class DetailView(generic.DetailView):
model = Profile
template_name = 'student/detail.html'

#Add student section
class ProfileCreate(generic.CreateView):
model = Profile
fields = ['firstName', 'middleName', 'lastName', 'dob', 'gender', 'parentsName', 'address',
'lga', 'Religion', 'email', 'phone', 'photo']

#Add Subject section
class CourseCreate(CreateView):
model = Course
fields = ['subject', 'score', 'grade']


def get_form_kwargs(self):
kwargs = super(CourseCreate, self).get_form_kwargs()
kwargs['instance'] = Course(pk=self.kwargs['pk'])
return kwargs

urls.py

urlpatterns = [
#index url
url(r'^$', views.IndexView.as_view(), name='index'),

url(r'^signup/$', views.UserFormView.as_view(), name='signup'),
#details
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
#profile/add
url(r'^profile/add/$', views.ProfileCreate.as_view(), name='profile-add'),
#course/add
url(r'^(?P<pk>[0-9]+)/course_form/$', views.CourseCreate.as_view(), name='course_form'),
#profile/pk for update
url(r'^profile/(?P<pk>[0-9]+)/$', views.ProfileUpdate.as_view(), name='profile-update'),
#profile/pk for deleting
url(r'^profile/(?P<pk>[0-9]+)/delete/$', views.ProfileDelete.as_view(), name='profile-delete'),
]


template
{% extends 'student/base.html' %}
{% block title %}{% endblock %}

{% block body %}

<div class="container subject-container">
<div class="row">
<!-- profile photo-->
<div class="col-sm-4 col-md-3">
<div class="panel panel-primary">
<div class="panel-heading">
<h1 class="panel-title">{{profile.lastName}} {{profile.firstName}}</h1>
</div>
<div class="panel-body">
<a href="{% url 'student:detail' <a href="http://profile.id" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;">profile.id %}">
{% if profile.photo %}
<img src="{{ profile.photo.url }}" class="img-thumbnail" width="250px" hieght="100px">
{% else %}
<p class="small">No image to display</p>
{% endif %}
</a>
</div>
</div>

</div>

<!-- Subject Add-->
<ul class="nav nav-pills" style="margin-bottom: 10px;">
<li role="presentation"><a href="{% url 'student:detail' <a href="http://profile.id" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;">profile.id %}">View All</a></li>
<li role="presentation" class="active"><a href="{% url 'student:course_form' <a href="http://profile.id" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;">profile.id %}">Add New Song</a></li>
</ul>
<div class="col-sm-12 col-md-7">
<div class="panel panel-success">
<div class="panel-heading">
<h1 class="panel-title">Add Subject</h1>
</div>
<div class="panel-body">
<h3>Add Subject</h3>
{% if error_message %}
<p><strong>{{ error_message }}</strong></p>
{% endif %}
<form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="hidden" name="profile" value="{{ profile }}">
{% include 'student/form-profile-temp.html' %}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>

</div>
</div>

</div>

</div>
</div>
{% endblock %}

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;">https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;">https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.
--

Mit besten Grüßen
Andy

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;">https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/CA%2B8CBRiZjbxssLZt8J%3Dst7i%3DM5b%3D8nhFasJMqUp_wYAEaWm_JA%40mail.gmail.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/CA%2B8CBRiZjbxssLZt8J%3Dst7i%3DM5b%3D8nhFasJMqUp_wYAEaWm_JA%40mail.gmail.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/CA%2B8CBRiZjbxssLZt8J%3Dst7i%3DM5b%3D8nhFasJMqUp_wYAEaWm_JA%40mail.gmail.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/CA%2B8CBRiZjbxssLZt8J%3Dst7i%3DM5b%3D8nhFasJMqUp_wYAEaWm_JA%40mail.gmail.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/61c6d7df-37f0-464e-9b7c-3f5c185a1033%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

anyi.lloyd@gmail.com
In reply to this post by anyi.lloyd@gmail.com
This <a href="{% url 'student:detail' profile.id %}">
But my views on the section of adding subject, please is it correct.

----- Reply message -----
From: "Andy" <[hidden email]>
To: "Django users" <[hidden email]>
Subject: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']
Date: Thu, Mar 8, 2018 20:00

which one of your calls to detail are failing?
<a href="{% url 'student:detail' profile.id %}">
or
reverse('student:detail', kwargs={'pk': self.pk})
?

if its the second one, try with args=[self.pk]

Am Donnerstag, 8. März 2018 19:48:44 UTC+1 schrieb anyi.lloyd:
Yes it is named profile.

----- Reply message -----
From: "Andy Grabow" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">an...@...>
To: <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@...>
Subject: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']
Date: Thu, Mar 8, 2018 05:18

Well, is it actually named profile inside the view? Rather than the default original? Check if the name is right and your profile is named profile in the template. 

<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">anyi....@... <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">anyi....@...> schrieb am Mi. 7. März 2018 um 20:15:
The profile already have an id. Just wanted to add to an existing profile in the db with generic view.


----- Reply message -----
From: "Andy" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">kaku...@...>
To: "Django users" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@...>
Subject: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']
Date: Wed, Mar 7, 2018 11:08

If you actually are inside the profile create view, the profile probably does not have an id yet and thats why the url lookup is failing. The ID will be created on first save of the object.

Am Dienstag, 6. März 2018 00:11:53 UTC+1 schrieb anyi.lloyd:
Am new to Django, please i need help here. Am trying to add a subject into a particular id using generic CreatView, i keeping getting errors
Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

models.py

from django.db import models
from datetime import date
from django.core.urlresolvers import reverse
from django.shortcuts import redirect


class Profile(models.Model):
firstName = models.CharField(max_length=30)
middleName = models.CharField(max_length=30)
lastName = models.CharField(max_length=30)
dob = models.DateField(blank=True, null=True)
stud_id = models.CharField(max_length=5000)
gender = models.CharField(max_length=10)
parentsName =models.CharField(max_length=30)
address = models.CharField(max_length=250)
lga = models.CharField(max_length=250)
Religion = models.CharField(max_length=50)
email = models.EmailField(max_length=70, null=True, blank=True, unique=True)
phone = models.CharField(max_length=11, unique=True)
photo = models.FileField()
Comment = models.CharField(max_length=250)

def get_absolute_url(self):
return reverse('student:detail', kwargs={'pk': self.pk})

def __str__(self):
return self.firstName

class Course(models.Model):
profile = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True)
subject = models.CharField(max_length=20)
score = models.CharField(max_length=20)
grade = models.CharField(max_length=20)

def get_absolute_url(self,):
return reverse('student:detail', kwargs={'pk': self.pk})

views.py
from django.views import generic
from django.views.generic import View
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy, reverse
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login
from .models import Profile, Course
from .forms import UserForm



#Index view
class IndexView(generic.ListView):
template_name = 'student/index.html'
context_object_name = 'all_profile'

def get_queryset(self):
return Profile.objects.all()

#Detail view
class DetailView(generic.DetailView):
model = Profile
template_name = 'student/detail.html'

#Add student section
class ProfileCreate(generic.CreateView):
model = Profile
fields = ['firstName', 'middleName', 'lastName', 'dob', 'gender', 'parentsName', 'address',
'lga', 'Religion', 'email', 'phone', 'photo']

#Add Subject section
class CourseCreate(CreateView):
model = Course
fields = ['subject', 'score', 'grade']


def get_form_kwargs(self):
kwargs = super(CourseCreate, self).get_form_kwargs()
kwargs['instance'] = Course(pk=self.kwargs['pk'])
return kwargs

urls.py

urlpatterns = [
#index url
url(r'^$', views.IndexView.as_view(), name='index'),

url(r'^signup/$', views.UserFormView.as_view(), name='signup'),
#details
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
#profile/add
url(r'^profile/add/$', views.ProfileCreate.as_view(), name='profile-add'),
#course/add
url(r'^(?P<pk>[0-9]+)/course_form/$', views.CourseCreate.as_view(), name='course_form'),
#profile/pk for update
url(r'^profile/(?P<pk>[0-9]+)/$', views.ProfileUpdate.as_view(), name='profile-update'),
#profile/pk for deleting
url(r'^profile/(?P<pk>[0-9]+)/delete/$', views.ProfileDelete.as_view(), name='profile-delete'),
]


template
{% extends 'student/base.html' %}
{% block title %}{% endblock %}

{% block body %}

<div class="container subject-container">
<div class="row">
<!-- profile photo-->
<div class="col-sm-4 col-md-3">
<div class="panel panel-primary">
<div class="panel-heading">
<h1 class="panel-title">{{profile.lastName}} {{profile.firstName}}</h1>
</div>
<div class="panel-body">
<a href="{% url 'student:detail' <a href="http://profile.id" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;">profile.id %}">
{% if profile.photo %}
<img src="{{ profile.photo.url }}" class="img-thumbnail" width="250px" hieght="100px">
{% else %}
<p class="small">No image to display</p>
{% endif %}
</a>
</div>
</div>

</div>

<!-- Subject Add-->
<ul class="nav nav-pills" style="margin-bottom: 10px;">
<li role="presentation"><a href="{% url 'student:detail' <a href="http://profile.id" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;">profile.id %}">View All</a></li>
<li role="presentation" class="active"><a href="{% url 'student:course_form' <a href="http://profile.id" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;">profile.id %}">Add New Song</a></li>
</ul>
<div class="col-sm-12 col-md-7">
<div class="panel panel-success">
<div class="panel-heading">
<h1 class="panel-title">Add Subject</h1>
</div>
<div class="panel-body">
<h3>Add Subject</h3>
{% if error_message %}
<p><strong>{{ error_message }}</strong></p>
{% endif %}
<form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="hidden" name="profile" value="{{ profile }}">
{% include 'student/form-profile-temp.html' %}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>

</div>
</div>

</div>

</div>
</div>
{% endblock %}

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;">https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;">https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.
--

Mit besten Grüßen
Andy

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;">https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/CA%2B8CBRiZjbxssLZt8J%3Dst7i%3DM5b%3D8nhFasJMqUp_wYAEaWm_JA%40mail.gmail.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/CA%2B8CBRiZjbxssLZt8J%3Dst7i%3DM5b%3D8nhFasJMqUp_wYAEaWm_JA%40mail.gmail.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/CA%2B8CBRiZjbxssLZt8J%3Dst7i%3DM5b%3D8nhFasJMqUp_wYAEaWm_JA%40mail.gmail.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/CA%2B8CBRiZjbxssLZt8J%3Dst7i%3DM5b%3D8nhFasJMqUp_wYAEaWm_JA%40mail.gmail.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/61c6d7df-37f0-464e-9b7c-3f5c185a1033%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5aa18c7d.c89edf0a.6c209.344c%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

anyi.lloyd@gmail.com
In reply to this post by anyi.lloyd@gmail.com
Ok i will try out the second one you gave now. Thanks 

Sent from my HTC

----- Reply message -----
From: "Andy" <[hidden email]>
To: "Django users" <[hidden email]>
Subject: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']
Date: Thu, Mar 8, 2018 20:00

which one of your calls to detail are failing?
<a href="{% url 'student:detail' profile.id %}">
or
reverse('student:detail', kwargs={'pk': self.pk})
?

if its the second one, try with args=[self.pk]

Am Donnerstag, 8. März 2018 19:48:44 UTC+1 schrieb anyi.lloyd:
Yes it is named profile.

----- Reply message -----
From: "Andy Grabow" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">an...@...>
To: <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@...>
Subject: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']
Date: Thu, Mar 8, 2018 05:18

Well, is it actually named profile inside the view? Rather than the default original? Check if the name is right and your profile is named profile in the template. 

<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">anyi....@... <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">anyi....@...> schrieb am Mi. 7. März 2018 um 20:15:
The profile already have an id. Just wanted to add to an existing profile in the db with generic view.


----- Reply message -----
From: "Andy" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">kaku...@...>
To: "Django users" <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@...>
Subject: Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']
Date: Wed, Mar 7, 2018 11:08

If you actually are inside the profile create view, the profile probably does not have an id yet and thats why the url lookup is failing. The ID will be created on first save of the object.

Am Dienstag, 6. März 2018 00:11:53 UTC+1 schrieb anyi.lloyd:
Am new to Django, please i need help here. Am trying to add a subject into a particular id using generic CreatView, i keeping getting errors
Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s) tried: ['(?P<pk>[0-9]+)/$']

models.py

from django.db import models
from datetime import date
from django.core.urlresolvers import reverse
from django.shortcuts import redirect


class Profile(models.Model):
firstName = models.CharField(max_length=30)
middleName = models.CharField(max_length=30)
lastName = models.CharField(max_length=30)
dob = models.DateField(blank=True, null=True)
stud_id = models.CharField(max_length=5000)
gender = models.CharField(max_length=10)
parentsName =models.CharField(max_length=30)
address = models.CharField(max_length=250)
lga = models.CharField(max_length=250)
Religion = models.CharField(max_length=50)
email = models.EmailField(max_length=70, null=True, blank=True, unique=True)
phone = models.CharField(max_length=11, unique=True)
photo = models.FileField()
Comment = models.CharField(max_length=250)

def get_absolute_url(self):
return reverse('student:detail', kwargs={'pk': self.pk})

def __str__(self):
return self.firstName

class Course(models.Model):
profile = models.ForeignKey(Profile, on_delete=models.CASCADE, null=True)
subject = models.CharField(max_length=20)
score = models.CharField(max_length=20)
grade = models.CharField(max_length=20)

def get_absolute_url(self,):
return reverse('student:detail', kwargs={'pk': self.pk})

views.py
from django.views import generic
from django.views.generic import View
from django.views.generic.edit import CreateView, UpdateView, DeleteView
from django.core.urlresolvers import reverse_lazy, reverse
from django.shortcuts import render, redirect
from django.contrib.auth import authenticate, login
from .models import Profile, Course
from .forms import UserForm



#Index view
class IndexView(generic.ListView):
template_name = 'student/index.html'
context_object_name = 'all_profile'

def get_queryset(self):
return Profile.objects.all()

#Detail view
class DetailView(generic.DetailView):
model = Profile
template_name = 'student/detail.html'

#Add student section
class ProfileCreate(generic.CreateView):
model = Profile
fields = ['firstName', 'middleName', 'lastName', 'dob', 'gender', 'parentsName', 'address',
'lga', 'Religion', 'email', 'phone', 'photo']

#Add Subject section
class CourseCreate(CreateView):
model = Course
fields = ['subject', 'score', 'grade']


def get_form_kwargs(self):
kwargs = super(CourseCreate, self).get_form_kwargs()
kwargs['instance'] = Course(pk=self.kwargs['pk'])
return kwargs

urls.py

urlpatterns = [
#index url
url(r'^$', views.IndexView.as_view(), name='index'),

url(r'^signup/$', views.UserFormView.as_view(), name='signup'),
#details
url(r'^(?P<pk>[0-9]+)/$', views.DetailView.as_view(), name='detail'),
#profile/add
url(r'^profile/add/$', views.ProfileCreate.as_view(), name='profile-add'),
#course/add
url(r'^(?P<pk>[0-9]+)/course_form/$', views.CourseCreate.as_view(), name='course_form'),
#profile/pk for update
url(r'^profile/(?P<pk>[0-9]+)/$', views.ProfileUpdate.as_view(), name='profile-update'),
#profile/pk for deleting
url(r'^profile/(?P<pk>[0-9]+)/delete/$', views.ProfileDelete.as_view(), name='profile-delete'),
]


template
{% extends 'student/base.html' %}
{% block title %}{% endblock %}

{% block body %}

<div class="container subject-container">
<div class="row">
<!-- profile photo-->
<div class="col-sm-4 col-md-3">
<div class="panel panel-primary">
<div class="panel-heading">
<h1 class="panel-title">{{profile.lastName}} {{profile.firstName}}</h1>
</div>
<div class="panel-body">
<a href="{% url 'student:detail' <a href="http://profile.id" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;">profile.id %}">
{% if profile.photo %}
<img src="{{ profile.photo.url }}" class="img-thumbnail" width="250px" hieght="100px">
{% else %}
<p class="small">No image to display</p>
{% endif %}
</a>
</div>
</div>

</div>

<!-- Subject Add-->
<ul class="nav nav-pills" style="margin-bottom: 10px;">
<li role="presentation"><a href="{% url 'student:detail' <a href="http://profile.id" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;">profile.id %}">View All</a></li>
<li role="presentation" class="active"><a href="{% url 'student:course_form' <a href="http://profile.id" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fprofile.id\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFutahCLo1BV1yj2d1lwgGlavbj8Q&#39;;return true;">profile.id %}">Add New Song</a></li>
</ul>
<div class="col-sm-12 col-md-7">
<div class="panel panel-success">
<div class="panel-heading">
<h1 class="panel-title">Add Subject</h1>
</div>
<div class="panel-body">
<h3>Add Subject</h3>
{% if error_message %}
<p><strong>{{ error_message }}</strong></p>
{% endif %}
<form class="form-horizontal" role="form" action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
<input type="hidden" name="profile" value="{{ profile }}">
{% include 'student/form-profile-temp.html' %}
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">Submit</button>
</div>
</div>
</form>

</div>
</div>

</div>

</div>
</div>
{% endblock %}

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;">https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;">https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.
--

Mit besten Grüßen
Andy

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe&#39;;return true;">https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="VG8HnX-uAAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">django...@....
Visit this group at <a href="https://groups.google.com/group/django-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/django-users&#39;;return true;">https://groups.google.com/group/django-users.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/django-users/CA%2B8CBRiZjbxssLZt8J%3Dst7i%3DM5b%3D8nhFasJMqUp_wYAEaWm_JA%40mail.gmail.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/django-users/CA%2B8CBRiZjbxssLZt8J%3Dst7i%3DM5b%3D8nhFasJMqUp_wYAEaWm_JA%40mail.gmail.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/django-users/CA%2B8CBRiZjbxssLZt8J%3Dst7i%3DM5b%3D8nhFasJMqUp_wYAEaWm_JA%40mail.gmail.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/django-users/CA%2B8CBRiZjbxssLZt8J%3Dst7i%3DM5b%3D8nhFasJMqUp_wYAEaWm_JA%40mail.gmail.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/By5BEzS0ZJE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/61c6d7df-37f0-464e-9b7c-3f5c185a1033%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5aa18cb8.c19cdf0a.5389e.7caa%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.