settings.py
STATIC_ROOT = os.path.join(BASE_DIR, 'static').replace('\\','/')
STATICFILES_DIRS =(
("css", os.path.join(STATIC_ROOT,'css').replace('\\','/')),
("js", os.path.join(STATIC_ROOT,'js').replace('\\','/')),
)
STATIC_URL = '/static/'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
#'DIRS': [],
'DIRS':TEMPLATE_DIRS,
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.core.context_processors.static',
],
},
},
]
其中’django.core.context_processors.static’
启用staticfiles
templates/table.html
<head>
<title>Changhong ID Search</title>
<link href="{{STATIC_URL}}css/bootstrap.min.css" rel="stylesheet">
<link href="{{STATIC_URL}}css/bootstrap.css" rel="stylesheet">
<link href="{{STATIC_URL}}css/bootstrap-theme.css" rel="stylesheet">
<link href="{{STATIC_URL}}css/bootstrap-theme.min.css" rel="stylesheet">
<script src="{{STATIC_URL}}js/jquery-2.1.1.min.js"></script>
<script src="{{STATIC_URL}}js/bootstrap.min.js"></script>
</head>
从浏览器访问发现STATIC_URL为空,应该是view方法中没有传contenxt_instance
加上之后就能通过{{STATIC_URL}}访问/static/
render_to_response('table.html',locals(),context_instance=RequestContext(request))