Reputation: 69
Here is my urlpatterns
urlpatterns = [
url(r'^volunteer/$', views.volunteerInformation, name='volunteerInformation'),
url(r'^volunteer/(?P<ID>[0-0]{1})/$', views.volunteerInformation, name='volunteerInformation'),
]
Here is the view that I'm trying to call
def volunteerInformation(request, ID=None):
volunteers = Volunteer.objects.all()
if ID:
print ID
else:
print "XKCD"
return render(request, 'dbaccess/volunteer.html', {'volunteers': volunteers})
When the url is .../volunteer/, it prints XKCD. But when the url is ..../volunteer/1, I'm getting an error that the page was not found. Here is the error:
^ ^volunteer/(?P<ID>[0-0]{1})/$ [name='indVolunteerInformation']
^ ^volunteer/$ [name='volunteerInformation']
^admin/
The current URL, volunteer/3, didn't match any of these.
What can I do about it?
Upvotes: 0
Views: 110
Reputation: 4511
Your url regex is wrong, you are searching for numbers of length 1 in the range 0-0. To match any number change this:
^volunteer/(?P<ID>[0-0]{1})/$
for something like
^volunteer/(?P<ID>\d+)/$
Upvotes: 2