[英]Django can not find the css file specified in html file
在我的Django项目中,我有一个html文件:
<link href="{{ STATIC_URL }}bootstrap/bootstrap.css" rel="stylesheet" type="text/css" media="screen">
并在settings.py中使用STATIC_URL ='/ static /'。 我的urls.py是:
urlpatterns = patterns('',
url(r'^$', WelcomeView.as_view(), name='welcome'),
)
我的Django项目无法在/static/
目录中找到bootstrap.css
文件。 我应该在urls.py
添加一个url吗? 那我应该写什么呢?
当我的html文件是:
{% load staticfiles %}
<link href="{% static bootstrap/bootstrap.css %}" rel="stylesheet" type="text/css" media="screen">
浏览器说:“ TemplateSyntaxError出现在/无法从'bootstrap / bootstrap.css'中解析剩余部分:'bootstrap / bootstrap.css'”
我的settings.py是:
import os
import sys
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
if ROOT_PATH not in sys.path:
sys.path.append(ROOT_PATH)
STATIC_ROOT = os.path.abspath(os.path.join(ROOT_PATH, '..', 'static'))
#STATIC_ROOT = /home/mysite/static
TEMPLATE_ROOT = os.path.join(ROOT_PATH, 'templates')
STATIC_URL = '/static/'
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'mysite',
# Uncomment the next line to enable the admin:
# 'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
您的目录如下所示:
-youproject
|___static
| |___ bootstrap
| |___bootstrap.css
|___templates
| |___yourhtml.html
|___vies.py
|___models.py
我的django专案就是这样。因此,请检查专案的目录。
希望可以帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.