在Django中加载CSS /图像 [英] Load CSS/images in Django
问题描述
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
如何加载我的 c code code code $ c> c $ c> b $ b
看看静态文件
: https://docs.djangoproject.com/en/dev/howto/static-files/
您需要:
- 添加
django.contrib.staticfiles
到您安装的应用程序 - 将您的文件放入
静态
目录 - 设置
STATIC_ROOT
和STATIC_URL $>
- 使用
STATIC_URL
变量或static $您的模板中的c $ c> templatetag
- 使用
{%load staticfiles%}
然后< link href ={%staticcommon.css%} =stylesheettype =text / css/>
在您的生产环境中,您需要收集静态文件
I've read the official Django Docs and many other posts here in SO. Still I'm unable to figure out the way to load my CSS files in HTML pages. I'm running Django 1.4
. Here is my whole structure of mysite
project having auth
as the app.
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
How can I load my common.css
file in index
and home
template files?
Take a look at static files
: https://docs.djangoproject.com/en/dev/howto/static-files/
You need to:
- add
django.contrib.staticfiles
to your installed apps - put your files in the
static
directory - set
STATIC_ROOT
andSTATIC_URL
in your settings - use the
STATIC_URL
variable or thestatic
templatetag in your templates
{% load staticfiles %}
and then <link href="{% static "common.css" %}" rel="stylesheet" type="text/css"/>
In your production environment you'll then need to collect the static files
这篇关于在Django中加载CSS /图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!