Django 站点 - 两个站点的不同 urls.py
我为我的客户维护一个 Django Web 应用程序。我们在 Django 中构建了它,对于计算机用户来说,它非常棒。我们现在希望迎合移动设备用户的需求。
除了模板切换之外,我们还需要以不同的方式工作。应用程序的视图的工作方式略有不同,但 URL 结构也需要简化。
我意识到我要要求的内容违反了 DRY 精神,但是有没有一个好的方法来分割 urls.py
,以便其中一半用于 ourdomain.com
另一半是m.ourdomain.com
?如果我能做到这一点,我可以添加 mobile_views.py
并编写新视图。
项目中启用了 Django 站点,但我很高兴使用硬编码的 request.domain.startswith('m.')
风格的 hack。看起来这可能会表现得更好 - 但我不知道如何从 URL 文件获取请求。
I maintain a Django webapp for a client of mine. We built it out in Django and for computer users, it's great. We now want to cater to mobile device users.
On top of a template switch, we also need things to work differently. The application will have views that work in a subtly different way but also the URL structure needs to be simplified.
I realise what I'm about to ask for violates the DRY ethos but is there a good way to split the urls.py
so that half of it is for ourdomain.com
and the other half is for m.ourdomain.com
? If I can do that, I can add a mobile_views.py
and write the new views.
Django's Sites is enabled in the project but I'm happy to use a hard-coded request.domain.startswith('m.')
-style hack. Seems like that might perform better - but I've no idea how one gets the request from the URLs file.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用中间件检测对其他站点的访问并设置
request.urlconf
到您要使用的其他 urlconf。Use middleware to detect the access to the other site and set
request.urlconf
to the other urlconf that you want to use.