【问题标题】:How to get the domain name in django view function? [duplicate]如何在django视图功能中获取域名? [复制]
【发布时间】:2014-05-04 08:44:00
【问题描述】:

我的应用程序将托管在多个域中,我需要一个 django 视图功能中的域名...如何实现?我正在使用 django 1.3.3。

我想要这样的东西

www.syz.com 127.0.0.1:8000

【问题讨论】:

    标签: python django


    【解决方案1】:

    看看request.get_host()

    文档:https://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.get_host

    或在您的模板中(如果您使用 requestContext){{request.get_host}}

    正如@jayanth-koushik 提到的,您可以在这里找到更多信息:How can I get the domain name of my site within a Django template?

    【讨论】:

      猜你喜欢
      • 2015-07-08
      • 1970-01-01
      • 2018-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-07
      • 2014-10-29
      相关资源
      最近更新 更多