在我的urls.py
我定义了这样的东西:
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'),
在视图中:
<a href="{% url 'filer:detail' file.id %}">{{ file.name }}</a>
<a href="{% url 'filer:delete' file.id %}"><img src="{% static 'filer/images/delete.png' %}" alt="delete" /></a>
根据文档,我可以做这样的事情:
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'),
)),
但是如果我更改为此包含模式,那么我会收到此错误:
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: []
我知道为什么我会收到这个错误 - 没有参数url(r'^\.html', detail, name='detail'),
- 我的问题是:如何使用包含在视图中的这个 url 模式{% url %}
?
Django:1.8.2 Python:3.4.2