【问题标题】:How can django dispatch visits to views based on domaindjango如何根据域调度对视图的访问
【发布时间】:2012-02-08 03:20:05
【问题描述】:

比如我有一个django项目,有两个页面。

http://domain.com/A/things

http://domain.com/B/things

现在我希望访问者可以通过 url 访问这些页面

http://A.domain.com/things

http://B.domain.com/things

我尝试使用 nginx 重写规则。比如将“http://A.domain.com/things”改写成“http://domain.com/A/things”

但是当我使用函数 reverse 或 templatetag url 时,url 仍然是 "/A/things" 而不是 "http://A.domain.com/things" em>

我们知道,django 会根据 url 调度对视图的访问。不知道有没有办法让django基于域进行分派访问?

【问题讨论】:

    标签: django nginx dns


    【解决方案1】:

    查看 django-hosts 应用程序。它为子域提供了非常方便的工作。

    https://github.com/ennio/django-hosts

    【讨论】:

    • 我可以推荐这个应用程序。请注意,它能够基于域进行切换,而不仅仅是子域 - 这在自述文件中可能并不明显。
    【解决方案2】:

    您可以在不同的 VirtualHosts 中拥有不同的 Django 项目,另一种选择是使用 Sites Framework

    【讨论】:

    • 我只想要一个数据库和一个仓库,所以我决定只在不同的虚拟主机中使用一个 django 项目。
    猜你喜欢
    • 1970-01-01
    • 2010-12-15
    • 2022-09-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    • 2014-04-19
    • 2015-04-07
    相关资源
    最近更新 更多