/project_root/
manage.py
/project/
/static/
/css/
/js/
/img/
/media/
settings.py
urls.py
这是我的文件夹结构。我的 settings.py 就像:
这是我的settings.py:
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static/')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(PROJECT_ROOT, 'staticfiles'),
)
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
urls.py:
urlpatterns = patterns('',
url(r'^$', 'employee.views.index'),
url(r'^admin/', include(admin.site.urls)),
)+ static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
urlpatterns += staticfiles_urlpatterns()
模板:
{% load static %}
{% load staticfiles %}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="{{ STATIC_URL }}img/logo48.png" rel="SHORTCUT ICON" />
<link href="{{ STATIC_URL }}css/master.css" rel="stylesheet" type="text/css" media="screen">
<link href="{{ STATIC_URL }}css/custom.css" rel="stylesheet" type="text/css" media="screen">
在视图源中,我可以看到:
<link href="/static/css/master.css" rel="stylesheet" type="text/css" media="screen">
<link href="/static/css/custom.css" rel="stylesheet" type="text/css" media="screen">
<link href="/static/css/fixes.css" rel="stylesheet" type="text/css" media="screen">
但是我的模板文件中没有加载 css。请指导我。