我是新的django框架。我创建了简单的欢迎页面,现在我想包括css文件在我的项目中。我不能在项目中应用css文件.i有错误,如“NetworkError:404 NOT FOUND -/static/css/hai.css”如何在django中为css和javascript使用静态文件夹?
这是我的项目结构
setting.py
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
STATIC_URL = '/static/'
TEMPLATE_DIRS=(
os.path.join(os.path.dirname(BASE_DIR),"static","templates"),
)
if DEBUG:
MEDIA_URL='/media/'
STATIC_ROOT=os.path.join(os.path.dirname(BASE_DIR),"static","static-only")
MEDIA_ROOT=os.path.join(os.path.dirname(BASE_DIR),"static","media")
STATICFILE_DIRS=(
os.path.join(os.path.dirname(BASE_DIR),"static","static"),
)
url.py
if settings.DEBUG:
urlpatterns += static(settings.STATIC_URL,document_root=settings.STATIC_ROOT)
urlpatterns += static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
个
base.html文件
<link href="/static/css/bootstrap.min.css" rel="stylesheet">
,我试图以下链接,但我不能应用CSS https://www.youtube.com/watch?v=8t80DMAAps8
您最好使用随文档提供的教程来学习,而不是使用随机的YouTube视频。 – Ngenator 2014-10-30 14:58:38