【问题标题】:django filefield returning localhost-prefixed URLdjango 文件字段返回以 localhost 为前缀的 URL
【发布时间】:2021-01-16 13:53:44
【问题描述】:

我试图不在设置中指定网络应用程序的完整路径,以使其尽可能便携。

然而,

对于MEDIA_URL="/media/",从 Django FileField 模型返回的 URL 是 http://localhost/media/...

使用MEDIA_URL="//example.com/media/",返回的网址是http://example.com/media/...

但是架构 (http/s) 和域 (example.com) 应该与请求页面的相匹配。我该怎么做?

Django 应用程序通过 Nginx 与 Gunicorn 结合使用。

【问题讨论】:

    标签: django nginx gunicorn


    【解决方案1】:

    听起来 nginx 和 Django 未配置为传递和使用 http 主机名(例如 X-Forwarded-Host 标头)。这看起来是个不错的答案 - https://stackoverflow.com/a/58044808/6865

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-26
      • 1970-01-01
      • 2015-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-30
      • 1970-01-01
      相关资源
      最近更新 更多