【问题标题】:Apache will not serve Django static filesApache 不会提供 Django 静态文件
【发布时间】:2014-11-24 08:24:42
【问题描述】:

所以我看到很多关于 Apache 不提供 Django 管理静态文件的信息,但由于某种原因,Apache 不提供任何静态文件。它理解并找到模板,但没有加载图像、css 或 javascript。

编辑 2:更新了两个文件以显示新设置

编辑:我添加了 STATIC_ROOT 并且我能够收集静态文件,但在服务器重新启动后它仍然无法提供它们。

我试过 ./manage.py collectstatic 并得到这个错误:

ImproperlyConfigured("You're using the staticfiles app "
django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without 
having set the STATIC_ROOT setting to a filesystem path.

我的 settings.py 文件在这里:

https://github.com/rchurch4/stackquestions/blob/master/settings.py

我的 nxt4.com.conf 文件在这里:

https://github.com/rchurch4/stackquestions/blob/master/nxt4.com.conf

如果有人能告诉我具体如何配置它,以便 Apache 为 django 的静态文件提供服务,那就太好了。我正在使用 mysql 数据库在 AWS 上运行 Ubuntu。服务器上站点的文件路径是:/home/ubuntu/nxt4.com/nxt4/

提前致谢

【问题讨论】:

  • 您说您已添加STATIC_ROOT - 您尚未将其添加到您链接的settings.py。另外,显示您的实际设置?
  • 实际设置是什么意思?对 Web 服务器来说是全新的,所以越具体越好。如果通过实际设置您的意思是 /etc/apache2/sites-enabled/nxt4.com.conf,那么它是在我输入此评论后将立即启动的最新编辑...

标签: django apache ubuntu amazon-web-services httpd.conf


【解决方案1】:

错误信息似乎很清楚:您没有设置STATIC_ROOT 设置,所以collectstatic 不知道将收集的文件放在哪里。从您的 httpd.conf 的外观来看,它似乎应该设置为“/home/ubuntu/nxt4.com/static/”

【讨论】:

  • 我能够在根目录中收集静态文件,但仍然无法为它们提供服务
猜你喜欢
  • 1970-01-01
  • 2012-03-19
  • 1970-01-01
  • 1970-01-01
  • 2012-12-01
  • 2017-08-04
  • 2016-11-26
  • 2017-09-02
  • 1970-01-01
相关资源
最近更新 更多