django 사용자 정의 404403500 페이지

989 단어 django
1. settings를 설정합니다.py
DEBUG = False

ALLOWED_HOSTS = ["*"] 

STATIC_URL = '/static/'
STATIC_ROOT = 'static

2. 주 urls 설정
from . import view
 
urlpatterns = [
    path('admin/', admin.site.urls),
    path('', view.index),
       ........
    #       ,       
    url(r'^static/(?P.*)$', static.serve,
        {'document_root': settings.STATIC_ROOT}, name='static')
]
#       
handler403 = view.page_permission_denied
handler404 = view.page_not_found
handler500 = view.page_inter_error

3. view를 설정합니다.py
 from django.shortcuts import render
 
def page_not_found(request):   
    return render(request, '404.html')
def page_permission_denied(request):
    return render(request, '403.html')
def page_inter_error(request):
    return render(request, '500.html')


4.templates에 404. 추가html,403.html,500.html

좋은 웹페이지 즐겨찾기