[英]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.