1

I am using new Django 1.8 app to learn Django.

I am stumped as to how to get this my simple url to be resolved by urls.py

I create the url in another view as:

<a href="/photoview/{{photo.id}}/"}>

I can successfully pass this url to the browser as:

http://localhost:8000/photoview/300/

I am expecting that this url can be matched by the urls.py expression:

url('r^photoview/(?P<id>\d+)/$', views.photoview),

But this is not working. I have tried variations of this but none have worked so far, such as:

url('r^photoview/(?P<id>[0-9]+)/$', views.photoview),

I get this message in browser when it fails to match

Page not found (404)
Request Method:     GET
Request URL:    http://localhost:8000/photoview/300/

Using the URLconf defined in asset.urls, Django tried these URL patterns, in this order:

^admin/
^$ [name='index']
^time/$
^about/$
^accounts/$
^photos/$
^tags/$
^users/$
r^photoview/(?P<id>\d+)/$
^static\/photos\/(?P<path>.*)$

The current URL, photoview/300/, didn't match any of these.

Appreciate any help getting this to work.

1 Answer 1

4

you have url('r^photoview/(?P<id>\d+)/$', views.photoview), you want url(r'^photoview/(?P<id>\d+)/$', views.photoview),

(Note the r is in front of the string, not the first character)

As noted in docs.djangoproject.com/en/1.8/topics/http/urls,

The 'r' in front of each regular expression string is optional but recommended. It tells Python that a string is “raw” – that nothing in the string should be escaped

Also note that you should use a friendly name in your url definition (e.g. photoview) and then use {% url 'photoview' photo.id %} in your template instead of hardcoding the URL pattern.

Sign up to request clarification or add additional context in comments.

2 Comments

Aah, totally missed that. Thanks.
{% url 'photoview' photo.id %} - don't forget the quotes around the name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.