Discussion:
Reverse for 'detail' with arguments '('',)' not found. 1 pattern(s)
anyi.lloyd
2018-03-05 23:11:53 UTC
Permalink
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 django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
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.
Andy
2018-03-07 10:08:30 UTC
Permalink
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.
Post by 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
['(?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
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)
return reverse('student:detail', kwargs={'pk': self.pk})
return self.firstName
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)
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
template_name = 'student/index.html'
context_object_name = 'all_profile'
return Profile.objects.all()
#Detail view
model = Profile
template_name = 'student/detail.html'
#Add student section
model = Profile
fields = ['firstName', 'middleName', 'lastName', 'dob', 'gender', 'parentsName', 'address',
'lga', 'Religion', 'email', 'phone', 'photo']
#Add Subject section
model = Course
fields = ['subject', 'score', 'grade']
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 django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
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.
a***@gmail.com
2018-03-07 19:14:18 UTC
Permalink
The profile already have an id. Just wanted to add to an existing profile in the db with generic view.

----- Reply message -----
From: "Andy" <***@gmail.com>
To: "Django users" <django-***@googlegroups.com>
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.pyfrom 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 django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
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 django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
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.
Andy Grabow
2018-03-08 04:18:31 UTC
Permalink
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.
Post by a***@gmail.com
The profile already have an id. Just wanted to add to an existing profile
in the db with generic view.
----- Reply message -----
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.
Post by 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
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)
return reverse('student:detail', kwargs={'pk': self.pk})
return self.firstName
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)
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
template_name = 'student/index.html'
context_object_name = 'all_profile'
return Profile.objects.all()
#Detail view
model = Profile
template_name = 'student/detail.html'
#Add student section
model = Profile
fields = ['firstName', 'middleName', 'lastName', 'dob', 'gender', 'parentsName', 'address',
'lga', 'Religion', 'email', 'phone', 'photo']
#Add Subject section
model = Course
fields = ['subject', 'score', 'grade']
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
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
<https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com?utm_medium=email&utm_source=footer>
.
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
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
<https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com?utm_medium=email&utm_source=footer>
.
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 django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
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.
a***@gmail.com
2018-03-08 18:47:41 UTC
Permalink
Yes it is named profile.

----- Reply message -----
From: "Andy Grabow" <***@freilandkiwis.de>
To: <django-***@googlegroups.com>
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. 

***@gmail.com <***@gmail.com> 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" <***@gmail.com>
To: "Django users" <django-***@googlegroups.com>
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.pyfrom 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 django-users+***@googlegroups.com.

To post to this group, send email to django-***@googlegroups.com.

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 django-users+***@googlegroups.com.

To post to this group, send email to django-***@googlegroups.com.

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 django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
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 django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
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.
Andy
2018-03-08 19:00:35 UTC
Permalink
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]
Post by a***@gmail.com
Yes it is named profile.
----- Reply message -----
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.
Post by a***@gmail.com
The profile already have an id. Just wanted to add to an existing profile
in the db with generic view.
----- Reply message -----
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.
Post by 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
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)
return reverse('student:detail', kwargs={'pk': self.pk})
return self.firstName
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)
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
template_name = 'student/index.html'
context_object_name = 'all_profile'
return Profile.objects.all()
#Detail view
model = Profile
template_name = 'student/detail.html'
#Add student section
model = Profile
fields = ['firstName', 'middleName', 'lastName', 'dob', 'gender', 'parentsName', 'address',
'lga', 'Religion', 'email', 'phone', 'photo']
#Add Subject section
model = Course
fields = ['subject', 'score', 'grade']
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
<javascript:>.
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
<https://groups.google.com/d/msgid/django-users/8ecfd645-1aa7-462b-90fb-9d78d0a0fc38%40googlegroups.com?utm_medium=email&utm_source=footer>
.
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
<javascript:>.
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
<https://groups.google.com/d/msgid/django-users/5aa03a0c.d2d0df0a.10931.a4ce%40mx.google.com?utm_medium=email&utm_source=footer>
.
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
<javascript:>.
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
<https://groups.google.com/d/msgid/django-users/CA%2B8CBRiZjbxssLZt8J%3Dst7i%3DM5b%3D8nhFasJMqUp_wYAEaWm_JA%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
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 django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
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.
a***@gmail.com
2018-03-08 19:18:17 UTC
Permalink
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" <***@gmail.com>
To: "Django users" <django-***@googlegroups.com>
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 %}">orreverse('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" <***@freilandkiwis.de>
To: <***@googlegroups.com>
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. 

***@gmail.com <***@gmail.com> 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" <***@gmail.com>
To: "Django users" <***@googlegroups.com>
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.pyfrom 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 django-***@googlegroups.com.

To post to this group, send email to ***@googlegroups.com.

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 django-***@googlegroups.com.

To post to this group, send email to ***@googlegroups.com.

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 django-***@googlegroups.com.

To post to this group, send email to ***@googlegroups.com.

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 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 django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
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 django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
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.
a***@gmail.com
2018-03-08 19:19:16 UTC
Permalink
Ok i will try out the second one you gave now. Thanks

Sent from my HTC

----- Reply message -----
From: "Andy" <***@gmail.com>
To: "Django users" <django-***@googlegroups.com>
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 %}">orreverse('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" <***@freilandkiwis.de>
To: <***@googlegroups.com>
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. 

***@gmail.com <***@gmail.com> 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" <***@gmail.com>
To: "Django users" <***@googlegroups.com>
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.pyfrom 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 django-***@googlegroups.com.

To post to this group, send email to ***@googlegroups.com.

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 django-***@googlegroups.com.

To post to this group, send email to ***@googlegroups.com.

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 django-***@googlegroups.com.

To post to this group, send email to ***@googlegroups.com.

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 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 django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
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 django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
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.
Continue reading on narkive:
Loading...