Django:如何动态加载不同的urlconf?
我想要做什么:
# urls.py
urlpatterns = patterns('',
(r'^info/(?P<user>[-\w+])/(?P<app>[-\w+])/', include(%app%.urls)),
)
应该显示给定用户为应用程序输入的特定信息。我希望 URL 方案保持这种状态。有可能吗?我认为命名空间可以解决问题,但官方文档太稀疏并且缺乏好的示例。
有人可以阐明这个问题吗?
What I'm trying to do:
# urls.py
urlpatterns = patterns('',
(r'^info/(?P<user>[-\w+])/(?P<app>[-\w+])/', include(%app%.urls)),
)
which should display specific information that given user entered for the app. And I want the URL scheme to stay this way. Is it even possible? I think namespaces would do the trick but official documentation is too sparse and lacks good examples.
Can someone shed some light on this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我理解正确,您正在尝试根据 url 中“app”元素的值动态包含不同的 urlconf。
我不明白命名空间与此有什么关系。很简单,没有办法做到这一点。 Urlconf 在启动时编译,因此不能动态包含不同的内容。
实现您想要的唯一方法是为 app 的每个值提供特定的 url,每个值都包含相关的 urlconf。
If I understand correctly, you're trying to dynamically include a different urlconf depending on the value of the 'app' element in your url.
I don't see what namespaces have to do with this. Quite simply, there's no way to do it. Urlconfs are compiled at startup, so can't include different things dynamically.
The only way to approach what you want is to have specific urls for each value of app, each including the relevant urlconf.