# 非调试模式时的404和500页面
if not settings.DEBUG:
urlpatterns += patterns('',
url(r'%s(?P<path>.*)$' % settings.MEDIA_URL[1:], 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
url(r'^500/$', 'django.views.generic.simple.direct_to_template', {'template': 'common/500.html'}),
url(r'^505/$', 'django.views.generic.simple.direct_to_template', {'template': 'common/500.html'}),
(r'^error/$', 'django.views.generic.simple.direct_to_template', {'template': 'common/500.html'}), #错误页面
(r'^404/$', 'django.views.generic.simple.direct_to_template', {'template': 'common/404.html'}), #错误地址
(r'^505/$', 'django.views.generic.simple.direct_to_template', {'template': 'common/500.html'}), #错误地址
if not settings.DEBUG:
urlpatterns += patterns('',
url(r'%s(?P<path>.*)$' % settings.MEDIA_URL[1:], 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
url(r'^500/$', 'django.views.generic.simple.direct_to_template', {'template': 'common/500.html'}),
url(r'^505/$', 'django.views.generic.simple.direct_to_template', {'template': 'common/500.html'}),
(r'^error/$', 'django.views.generic.simple.direct_to_template', {'template': 'common/500.html'}), #错误页面
(r'^404/$', 'django.views.generic.simple.direct_to_template', {'template': 'common/404.html'}), #错误地址
(r'^505/$', 'django.views.generic.simple.direct_to_template', {'template': 'common/500.html'}), #错误地址
)
或者
handler404 = 'apps.views.main.page_not_found'
handler500 = 'apps.views.main.server_error'