Django关闭debug模式也就是:
在settings.py里面把DEBUG设置成False
DEBUG = False
但是问题就出来了,报500了
下面是部分解决方案,在settings.py你应该很容易配置下面这部分代码:
import os
HERE = os.path.dirname(os.path.dirname(__file__))
# Absolute filesystem path to the directory that will hold user-uploaded files.
# Example: "/var/www/example.com/media/"
MEDIA_ROOT = os.path.join(HERE,'media').replace('\\','/')
# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash.
# Examples: "http://example.com/media/", "http://media.example.com/"
MEDIA_URL = '/media/'
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/var/www/example.com/static/"
STATIC_ROOT = os.path.join(HERE,'static').replace('\\','/')
# URL prefix for static files.
# Example: "http://example.com/static/", "http://static.example.com/"
STATIC_URL = '/static/'
然后,
在你的templates文件夹下(或者其他你自定义的模版目录)
放好相关的500和404的模版,模版名字一定要是500.html,404.html
配置你的urls.py,你应该能看懂这种写法,不影响你本身配置的那部分,只用在后面加上就行了:
from django.conf.urls import patterns, include, url
from django.conf.urls import static
from django.conf import settings
urlpatterns +=patterns('',
url(r'^static/(?P<path>.*)$','django.views.static.serve',{'document_root':settings.STATIC_ROOT}),
url(r'^static/<?P<path>.*>$','django.views.static.serve',{'document_root':settings.MEDIA_ROOT}),
)
这样你就可以正常访问你的工程和在报错的情况下出现相应的自定义500页面和404页面了。