如何在 Django 中使用动态第一部分来嵌套 url 命名空间

发布于 2024-12-01 02:23:55 字数 586 浏览 0 评论 0原文

我有一个以房间为中心的应用程序。这些聊天室的成员可以在其中发布内容。我认为拥有 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 技术交流群。

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

发布评论

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

评论(1

苍风燃霜 2024-12-08 02:23:55

看起来这个问题最近已经修复了。 https://code.djangoproject.com/changeset/16608

Looks like this has been fixed recently. https://code.djangoproject.com/changeset/16608

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