我的 settings.py包含以下配置参数。
STATIC_ROOT = ''
STATIC_URL = '/static/'
# Additional locations of static files
STATICFILES_DIRS = (
'C:/Users/ABC/Desktop/DBMS/DjangoProject/tvshows',
)
我项目的 CSS 文件位于 C:/Users/ABC/Desktop/DBMS/DjangoProject/tvshows/static/default.css .
我有一个应该提取 CSS 内容的模拟 HTML 文件,但 URL 是 404。
<link rel="stylesheet" href="{{ STATIC_URL }}static/default.css" />
我做错了什么?
请您参考如下方法:
要检查的事情:
DEBUG = True在 settings.py 中-
from django.contrib.staticfiles.urls import staticfiles_urlpatterns # ... the rest of your URLconf goes here ... urlpatterns += staticfiles_urlpatterns() 使用
context processor或load static如果{{ STATIC_URL }}不工作If {{ STATIC_URL }} isn't working in your template, you're probably not using RequestContext when rendering the template.
As a brief refresher, context processors add variables into the contexts of every template. However, context processors require that you use RequestContext when rendering templates. This happens automatically if you're using a generic view, but in views written by hand you'll need to explicitally use RequestContext To see how that works, and to read more details, check out Subclassing Context: RequestContext.
