如何在 Django 中使用动态第一部分来嵌套 url 命名空间
我有一个以房间为中心的应用程序。这些聊天室的成员可以在其中发布内容。我认为拥有 url 模式的方式是这样的
# global urls.py
(r'^g/', include('elearning.apps.rooms.urls', namespace='rooms')),
# rooms urls.py
url(r'^(?P<room_slug>[-\w]+)/postari/',
include('elearning.apps.posts.urls', namespace='posts')),
# posts urls.py
url(r'^adauga/$', 'add', name='add'),
我的问题是我不知道如何从“帖子”应用程序反转视图的 URL。这样做
reverse('rooms:posts:add', kwargs={'room_slug': room.slug})
会引发 NoReverseMatch 错误,可能是因为“room_slug”与“add”视图的 URL 模式匹配。
我该怎么做?
谢谢
I have an application which is centered around rooms. These rooms have members who can post content in them. The way I thought of having the url patterns would be something like this
# global urls.py
(r'^g/', include('elearning.apps.rooms.urls', namespace='rooms')),
# rooms urls.py
url(r'^(?P<room_slug>[-\w]+)/postari/',
include('elearning.apps.posts.urls', namespace='posts')),
# posts urls.py
url(r'^adauga/
My issue is that I don't know how I can reverse the URL of a view from the 'posts' app. Doing
reverse('rooms:posts:add', kwargs={'room_slug': room.slug})
raises a NoReverseMatch error, probably because 'room_slug' is matched agains the 'add' view's URL pattern.
How can I do this?
Thanks
, 'add', name='add'),
My issue is that I don't know how I can reverse the URL of a view from the 'posts' app. Doing
raises a NoReverseMatch error, probably because 'room_slug' is matched agains the 'add' view's URL pattern.
How can I do this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来这个问题最近已经修复了。 https://code.djangoproject.com/changeset/16608
Looks like this has been fixed recently. https://code.djangoproject.com/changeset/16608