Django自定義404頁(yè)面
項(xiàng)目地址:https://github.com/ylpxzx/lifeblog
步驟
- DEBUG =True 改為 DEBUG =False
- ALLOWED_HOSTS = [] 改為 ALLOWED_HOSTS = [‘*’],
- 配置靜態(tài)路徑和靜態(tài)template,
- 在app下編寫404錯(cuò)誤處理視圖
def page_not_found(request,exception):
return render(request, '404.html')
- 在根urls配置404處理handler
from app.views import page_not_found # 加入該行
urlpatterns = [
path('admin/', admin.site.urls),
url(r'', include('ckeditor_uploader.urls')),
url(r'',include('post.urls')),
url(r'^search/', include(haystack.urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += staticfiles_urlpatterns()
handler404 = page_not_found # 加入該行
- 開(kāi)啟nginx和gunicorn的情況下,需要關(guān)閉nginx并殺死gunicorn,重新啟動(dòng)nginx和gunicorn