django提供静态CSS文件 [英] django serving static css files
问题描述
当我尝试运行url时,不应用CSS到我的模板python manage.py runserver窗口显示以下错误
[01 / Jan / 2013 20:00:40]GET / home / prat / PROJECT_ROOT / SOURCE_ROOT / static / css / Style.css HTTP / 1.1404 2207
有人可以指点我如何调试这个。我已经阅读了多个stackoverflow问题,并在我的settings.py中添加了以下设置。
PROJECT_R = os.path.abspath(os .path.dirname(__ name__))
PROJEECT_R = PROJECT_R +../
STATIC_ROOT = os.path.join(PROJECT_R,static)
STATIC_URL ='static /'
。
├──manage.py
├──README
├──SOURCE_ROOT
│├──__init__.py
│├──__init __。pyc
│├──settings.py
│├──settings.pyc
│├──urls.py
│├──urls.pyc
│├── wsgi.py
│└──wsgi.pyc
├──静态
│├──css
││├──README
││└── Style.css
│├──图片
││└──README
│└──js
│└──README
├──模板
│├──base.html
我通常在管理动态项目根目录:
from os.path import dirname,realpath,join
PROJECT_ROOT = dirname (realpath(__ file__))
然后进一步下面,静态根:
STATIC_ROOT = join(PROJECT_ROOT,'static /')
然后你引用静态文件,如下所示:
{{STATIC_URL}} css / Style.css
编辑:
请参阅文档获取更多信息。
I am relatively new to Django development.I have a css file inside a /static/css directory.
When I try to run the url no CSS is applied to my template. the python manage.py runserver window shows following error
[01/Jan/2013 20:00:40] "GET /home/prat/PROJECT_ROOT/SOURCE_ROOT/static/css/Style.css HTTP/1.1" 404 2207
Can someone please point me how to debug this. I have read multiple stackoverflow questions and added the following setting in my settings.py.
PROJECT_R = os.path.abspath(os.path.dirname(__name__))
PROJEECT_R = PROJECT_R + "../"
STATIC_ROOT = os.path.join(PROJECT_R, "static")
STATIC_URL = 'static/'
.
├── manage.py
├── README
├── SOURCE_ROOT
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── settings.py
│ ├── settings.pyc
│ ├── urls.py
│ ├── urls.pyc
│ ├── wsgi.py
│ └── wsgi.pyc
├── static
│ ├── css
│ │ ├── README
│ │ └── Style.css
│ ├── images
│ │ └── README
│ └── js
│ └── README
├── template
│ ├── base.html
Here's how I usually go about managing dynamic project root:
from os.path import dirname, realpath, join
PROJECT_ROOT = dirname(realpath(__file__))
And then further below, the static root:
STATIC_ROOT = join(PROJECT_ROOT, 'static/')
And then you reference static files like so:
{{ STATIC_URL }}css/Style.css
EDIT:
See the documentation for more information.
这篇关于django提供静态CSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!