【发布时间】:2011-06-18 09:35:28
【问题描述】:
如何查看我的静态 css 文件?我已经设置了我的 STATIC_ROOT,并且正在使用 python manage.py runserver。
在我的开发环境中,根据the docs,我只需要将我的静态文件(本例中为/static/css/typography.css)放在我的STATIC_ROOT中,python manage.py runserver 如果我有DEBUG = True,将自动创建访问它所需的视图。
STATIC_ROOT = os.path.join(os.path.abspath(os.path.dirname(__file__)), "static")
我也尝试在 URLConf 中手动添加视图,它也不会显示 css 文件:
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# ... the rest of your URLconf goes here ...
urlpatterns += staticfiles_urlpatterns()
在我的模板中,{{ STATIC_URL }} 到达了正确的地址 (/static/css/typography.css),但是当我尝试访问它时它不会提供文件:
<link href="{{ STATIC_URL }}css/typography.css" rel="stylesheet" type="text/css">
注意:StackOverflow 上其他与 Django 相关的静态文件问题已有两年多的历史了。 Django 1.3b1 版本区分了 STATIC(静态文件,例如 css 和图像)和 MEDIA(用户上传的文件)。
【问题讨论】:
-
更准确地说,您将 STATIC_URL 设置为什么?