Django反向错误NoReverseMatch [英] django reverse error NoReverseMatch
本文介绍了Django反向错误NoReverseMatch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑到以下情况
views.py
return redirect('order-review', order=order.id)
urls.py
url(r'^review/$', 'checkout.views.review', {'order': '0'}, name="order-review"),
瞄准
views.py
def review(request, order):
真的有明显的解决方法吗?我只是看不到我出了什么问题,而django docco在传递变量时对示例略有了解.
is there a really obvious fix? I just can't see what i've got wrong and the django docco is slightly light on examples when passing a variable through.
推荐答案
它无法解析,因为您的网址格式实际上将 order 值硬编码(该值始终为"0").
It doesn't resolve, because your url pattern actually hard-codes the order value (it will always be '0').
您必须提供一种从URL本身更改 order 值的方法.
You have to provide a way to change the order value from within the URL itself.
准确地说:
urls.py
url(r'^review/$', 'checkout.views.review', {'order':'0'}, name="order-review-default-fallback"),
url(r'^review/(?P<order>[\d]+)/$', 'checkout.views.review', {}, name="order-review"),
应该解决您的问题.
这篇关于Django反向错误NoReverseMatch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文