urls.py
from django.conf.urls import url,include
from django.views.static import serve
from ***.settings import STATIC_ROOT
urlpatterns = [
……
url(r'^static/(?P<path>.*)', serve, {"document_root": STATIC_ROOT }),
]
# 全局404页面配置
handler404 = 'users.views.pag_not_found'
# 全局500页面配置
handler500 = 'users.views.page_error'
views.py
def pag_not_found(request):
"""
全局404配置函数
"""
from django.shortcuts import render_to_response
response = render_to_response('404.html', {})
response.status_code = 404
return response
def page_error(request):
"""
全局500配置函数
"""
from django.shortcuts import render_to_response
response = render_to_response('500.html', {})
response.status_code = 500
return response
setting.py
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False
ALLOWED_HOSTS = ['*']
……
STATIC_ROOT = os.path.join(BASE_DIR, 'static')