无法解析 Django“NoReverseMatch” kwargs 的例外
我无法让 Django 反向解析以下命名的 url -
URLconf 条目:
url(r'^shotmanager/(?P<shotid>\d+)/$', 'ctac.views.shotManager', {'message': "", 'errors': []}, name = 'shot-manager')
HttpResponseRedirect 调用:
return HttpResponseRedirect(reverse("shot-manager", kwargs={'shotid': id, 'message': s, 'errors': errorList}))
我在 Django 文档中没有看到任何内容表明我不能在 url 中混合 kwargs 和 url 中的字典条目。由于某种原因,如果我只发送“shotid”,反向就能很好地解决。
我已经访问过以下线程
Reversing Django URLs With Extra Options
并进行了研究它。目前还不清楚是否已解决。
I have am unable to get Django to reverse-resolve the following named url -
URLconf entry :
url(r'^shotmanager/(?P<shotid>\d+)/
HttpResponseRedirect call:
return HttpResponseRedirect(reverse("shot-manager", kwargs={'shotid': id, 'message': s, 'errors': errorList}))
I see nothing in the Django docs that suggests I cannot mix kwargs in the url and the dictionary entry in the url. For some reason, reverse will resolve fine if I only send it "shotid".
I have already visited the following thread
Reversing Django URLs With Extra Options
and have studied it. It is unclear if it was resolved either.
, 'ctac.views.shotManager', {'message': "", 'errors': []}, name = 'shot-manager')
HttpResponseRedirect call:
I see nothing in the Django docs that suggests I cannot mix kwargs in the url and the dictionary entry in the url. For some reason, reverse will resolve fine if I only send it "shotid".
I have already visited the following thread
Reversing Django URLs With Extra Options
and have studied it. It is unclear if it was resolved either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
reverse
返回一个 URL,其中填充了您在 args 或 kwargs 中传递的值。但您尝试生成的 URL 没有用于message
的空间。它会出现在生成的 URL 中的什么位置?编辑回复评论
如果您想在页面视图之间传递消息,正确的方法不是通过 URL,而是通过会话。 Django 甚至包含一个 消息传递框架 来为您管理此操作。
reverse
returns a URL populated with the values you pass in the args or kwargs. But the URL you are trying to generate hasn't got a space formessage
. Where would it go in the generated URL?Edit in response to comment
If you want to pass messages between page views, the correct way to do it is not via the URL, but by via the session. Django even includes a messaging framework to manage this for you.