Django: urls with common prefix and {% url %} with param in view

234 views Asked by At

In my urls.py i have defined something like this:

url(r'file-(?P<fid>\d+)\.html', detail, name='detail'),
url(r'file-(?P<fid>\d+)/history', history, name='history'),
url(r'file-(?P<fid>\d+)/edit', edit, name='edit'),
url(r'file-(?P<fid>\d+)/comments', comments, name='comments'),
url(r'file-(?P<fid>\d+)/delete', delete, name='delete'),

and in the view:

<a href="{% url 'filer:detail' file.id %}">{{ file.name }}</a>&nbsp;
<a href="{% url 'filer:delete' file.id %}"><img src="{% static 'filer/images/delete.png' %}" alt="delete" /></a>

and according to docs I can do something like this:

url(r'^file-(?P<fid>\d+)', include(
    url(r'^\.html', detail, name='detail'),
    url(r'^/history', history, name='history'),
    url(r'^/edit', edit, name='edit'),
    url(r'^/comments', comments, name='comments'),
    url(r'^/delete', delete, name='delete'),
)),

but if I change to this include pattern then I get this error:

NoReverseMatch at /files/

Reverse for 'detail' with arguments '(2,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []

Request Method: GET
Request URL:    xxx.xxx.xxx.xxx
Django Version: 1.8.2
Exception Type: NoReverseMatch
Exception Value: Reverse for 'detail' with arguments '(2,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []

I know why I get this error - there are no params in url(r'^\.html', detail, name='detail'), - and my question is: how to use this url patterns with include in views using {% url %}?

Django: 1.8.2 Python: 3.4.2

0

There are 0 answers