python - collectstatic 生成的文件未在 Django 中提供

标签 python css django django-staticfiles

我有一堆正在使用 collectstatic 处理的 css/js 文件。它们在我的 staticfiles 目录中成功创建,并附加了数字。

(env)zain@gandalf ~/projects/xxx[master*]$ ls staticfiles/css/
agreements.6cb653c1aa93.css  

在我的模板中,我使用 {% load static from staticfiles %} 并使用 static 标签加载静态资源。但是,不会插入由 collectstatic 生成的文件——而是使用我的静态文件夹中的文件。

对于如何在静态文件中提供 agreements.6cb653c1aa93.css 文件而不是静态的 agreements.css 文件,我将不胜感激。

设置/base.py

BASE_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), '../')
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'static'),
)

谢谢!

编辑 - 我正在使用白噪声:http://whitenoise.readthedocs.org/en/latest/django.html#add-gzip-and-caching-support

最佳答案

在生产中,Django 本身不提供文件。为此,您需要使用 Web 服务器(Apache、nginx 等)。

请参阅配置示例的文档:https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/#serving-files

关于python - collectstatic 生成的文件未在 Django 中提供,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30632874/

相关文章:

python - 检测 numpy 数组中的有序对

python - 将 Pandas Data Frame 放入现有 Excel 工作表

javascript - 解决 POP UP 窗口调整大小问题

python - 将 GAE 应用程序迁移到 Python 2.7 后出现 wsgi.py 错误

django - 将 {% url %} 传递给 Django 中的自定义模板标签

python - numpy recfromcsv 和 genfromtxt 跳过数据文件的第一行

python - 将数据与另一个数据框中两列中的数据进行比较以填充第一个数据框中的第三列

css - 格式化 bootstrap 导航链接 css

jquery - 我如何将 jQuery idTabs 更改为 Accordion

javascript - 在html中单击后创建onClick内容