Debug为True时,抛个异常就把代码、配置暴露出去了,所以上线要改成False
具体修改转自:http://blog.csdn.net/u013887008/article/details/51147134
1.在settings.py中设置这些:
- # 部署网站时
- DEBUG = False
- # 添加域名
- ALLOWED_HOSTS = ['localhost']
- # 静态文件 cs/js
- STATIC_URL = '/static/'
- STATICFILES_DIRS = (
- os.path.join(BASE_DIR, 'static'),
- )
- STATIC_ROOT = (
- os.path.join(BASE_DIR, 'static').replace('\\','/')
- )
- # 上传图片
- MEDIA_ROOT = os.path.join(BASE_DIR, 'media').replace('\\', '/')
- MEDIA_URL = '/media/'
2. 在url.py中加入
- url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),
- url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),
3. 在project的根目录下创建400.html, 500.html, 404.html,即可访问自己定义的error page页面