Django 应用程序位于自己的子域上
我有以下目录结构:
/ (index) /blog/ /about/
仅运行一个 Django 实例,我希望 URL 显示为 blog.domain.com (对于我的博客应用程序),但所有其他 URL 在 (www.)domain.com/ 下运行。
我当然可以对链接进行硬编码,强制进行此设置(基本上网络服务器将侦听 blog.domain.com 并转发为domain.com/blog/,但用户仍然会看到 blog.domain.com),但我想能够以正确的方式解析我的 URL 配置,但仍然让它们指向 domain.com 或 blog.domain.com,具体取决于正在解析的 url(应用程序)。
有没有好的方法可以做到这一点?我正在考虑使用自定义模板标签来代替 {% url my_resolve_name slug="test" as test %}
。
I've got the following directory structure:
/ (index) /blog/ /about/
Running only one Django instance, I want the URL to display as blog.domain.com (for my blog app), but all the other URLs to run under (www.)domain.com/.
I could surely hardcode the links, forcing this setup (basically the webserver will listen to blog.domain.com and do a forward as domain.com/blog/ but the user will still see blog.domain.com) but I want to be able to resolve my URL-configs the proper way but still get them to point to domain.com or blog.domain.com depending on the url (app) being resolved.
Is there a good way of doing this? I was thinking of a custom templatetag to use instead of {% url my_resolve_name slug="test" as test %}
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它没有内置支持,但很多人(包括我)都以一种黑客的方式完成了它。
http://uswaretech.com/blog/2008/10/using -subdomains-with-django/
http://uswaretech.com/django-subdomains/
There is no builtin support for it, but many people (including me) have done it in a hackish sort of way.
http://uswaretech.com/blog/2008/10/using-subdomains-with-django/
http://uswaretech.com/django-subdomains/
在 nginx 上尝试一下:
这会将 blog.example.com/some/params/ 的所有请求重写为 www.example.com/blog/some/params
try this on nginx:
this rewrites all requests to blog.example.com/some/params/ to www.example.com/blog/some/params