问题
I'm having a problem with this error:
Caught NoReverseMatch while rendering: Reverse for ''pennies.views.seed_preview''
with arguments '()' and
keyword arguments '{'sa': 1724158887L, 'sh': 31L}' not found.
which is produced by this bit of template:
<a href="{% url 'pennies.views.seed_preview' sh=seed.id sa=seed.salt %}">
Preview</a>
and this bit of url.py
url(r'^seedpreview/sh=(?P<shareable_id>\d+)/sa=(?P<salt>\d+)$', \
'pennies.views.seed_preview'),
and this function signature
def seed_preview(request, shareable_id, salt):
(and url from future, of course). And the error suggests to me that django has captured the right dictionary to find my function. Reading templatetags/future.py also leaves me thinking I've done it right, but clearly I haven't.
Any pointers?
回答1:
you are using the wrong keys, it should be
{% url 'pennies.views.seed_preview' shareable_id=seed.id salt=seed.salt %}
回答2:
You need to load the future url template tag in every template where you use it. Loading a template tag library does not make it available to parent or child templates.
For more info see the Django docs on Custom libraries and template inheritance
来源:https://stackoverflow.com/questions/8029820/noreversematch-with-url-and-keyword-args