Django似乎从静态文件URL中删除了https - 为什么?

时间:2016-04-24 18:14:41

标签: django https static-files

刚刚将我的网站切换为通过SSL提供服务,我无法让Django接收正确生成的网址:s表示静态文件。

我的STATIC_URL设置采用https://example.com/assets/static/

的形式

当我在模板中{% static 'css/file.css' %}时,路径显示为http://example.com/assets/static/css/file.css - 与之前相同。

我试图解决这个问题:

  • 确保我使用正确的设置进行最新提交。
  • python manage.py collectstatic
  • 重新启动nginx / gunicorn / memcached
  • 已删除*.pyc个文件,以防万一

同样的事情发生在MEDIA_URL上。但是,如果我进入交互式shell并导入模型,然后打印出上传图像文件的.url属性(例如),则会显示正确的https:// - 前缀。< / p>

运行Django 1.9.5,使用CachedStaticFileLoader获取静态文件,Gunicorn(v 19.4)和模板缓存。缓存引擎是memcached。

有关正在发生的事情的任何想法?

修改:虽然其他代码更改似乎有效,但STATIC_URLMEDIA_URL的设置更改根本没有被提取。我不知道发生了什么......

1 个答案:

答案 0 :(得分:2)

The answer was that no settings changes were picked up at all – the Gunicorn process was hung up trying to restart somehow (no matter how many times I told it to), keeping the old process going. Changes to templates etc got picked up (as those are not python files), but the STATIC_URL was never updated.

Stupidly simple answer: reboot ALL THE THINGS.