python - Django understanding urls -



python - Django understanding urls -

in core urls.py, have

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

in studentportal.urls, have 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 popping while rendering template @ 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 pretty sure error in way of using urls , not in views, nor templates. also, exclusion of '$' @ end of urlpatterns results in noreversematch errors. though i've read django documentation urlpatterns. '^' means start of line '$' means url should end here '(?p< named_variable >)' used grab variable url.

so why pattern not matching when first pattern should match 'viewproject' arguments '('10',)' ?

to match non-single-digit numbers, alter to:

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

or

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

python django django-urls

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -