我已经在SO中阅读了官方Django文档和许多其他帖子。我仍然无法弄清楚在HTML页面中加载CSS文件的方法。我正在运行Django 1.4
。以下是mysite
项目的整个结构,auth
为应用。
mysite/
manage.py
settings.py
__init__.py
urls.py
auth/
__init__.py
forms.py
models.py
views.py
templates/
index.html
home.html
media/
common.css
如何在common.css
和index
模板文件中加载home
文件?
答案 0 :(得分:3)
查看static files
:https://docs.djangoproject.com/en/dev/howto/static-files/
你需要:
django.contrib.staticfiles
添加到已安装的应用static
目录STATIC_ROOT
和STATIC_URL
STATIC_URL
变量或static
模板标签 {% load staticfiles %}
然后<link href="{% static "common.css" %}" rel="stylesheet" type="text/css"/>
在生产环境中,您需要收集静态文件