无法解析 Django“NoReverseMatch” kwargs 的例外

发布于 2024-10-01 01:51:16 字数 669 浏览 2 评论 0原文

我无法让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜还是长夜 2024-10-08 01:51:16

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 for message. 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文