NoReverseMatch with {% url … %} and keyword args

醉酒当歌 提交于 2019-12-02 01:30:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!