0
votes

In my core urls.py, I have

url(r'^student/', include('studentportal.urls')),

In studentportal.urls, I have this url

    url(r'^project/(?P<project_id>[0-9])/edit/$', views.editproject, name='editproject'),   
    url(r'^project/(?P<project_id>[0-9])/upload/$', views._upload, name='upload_document'),
    url(r'^project/(?P<project_id>[0-9])/$', views.viewproject, name='viewproject'),
    url(r'^download/(?P<document_id>[0-9])/', views.download, name='download_document'),

NoReverseMatch errors are popping up while rendering the template at this line

<p><a class="btn btn-default" href="{% url 'viewproject' p.id %}" role="button">View details »</a></p> 

It checks these urls

2 pattern(s) tried: ['student/project/(?P<project_id>[0-9])/$', '$project/(?P<project_id>[0-9])/$']

I am pretty sure that the error is in my way of using the urls and not in views, nor templates. Also, the exclusion of '$' at the end of the urlpatterns results in NoReverseMatch errors. Even though I've read the django documentation about the urlpatterns.
'^' means the start of the line
'$' means that the url should end here
'(?P< named_variable >)' is used to catch a variable from the url.

So why is the pattern not matching when clearly the first pattern should match 'viewproject' with arguments '('10',)' ?

1
why does your second URL group start with a $ ?karthikr
@karthikr thats because I am sending the url(r'^$') to the same url file (studentportal.urls). The empty url is finally caught in the nested url file and linked to a viewdarkryder
Are you sure p.id is 10? View source code.GAEfan
And, if the url doesn't end in a slash, it won't match anything. I would remove the trailing slashes from your url patterns. Paste the href url from your template's source code.GAEfan
@GAEfan I found out something else while debugging. There are many projects for every student and I'm using a for loop to render them. Now I realised that the projects' id's are these: 6, 7, 8, 10, 12, 14. So, the template error comes up when handling non single digit numbers. I did remove the trailing slash. However that resulted in /projects/10 being caught as '/projects/1'darkryder

1 Answers

3
votes

To match non-single-digit numbers, change to:

url(r'^project/(?P<project_id>[0-1000])/edit/$

or

url(r'^project/(?P<project_id>[0-9]+)/edit/$