myapp/url.py:
handler404 = 'blog.views.not_found'
handler500 = 'blog.views.server_error'
观点:
def not_found(request, exceptions):
return render(request, 'error/404.html')
def server_error(request):
return render(request, 'error/500.html')
settings.py:
DEBUG = False
ALLOWED_HOSTS = ['*']
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'staff.context_processors.staff_base',
'blog.context_processors.cart',
'blog.context_processors.setting',
],
},
},
]
WSGI_APPLICATION = 'config.wsgi.application'
404.html:
{% extends 'blog/base.html' %}
{% load static %}
{% block title %}400{% endblock title %}
{% block content %}
<p>404 Error</p>
{% endblock content %}
在DEBUG = True
中显示常规404错误,但在DEBUG = False
中显示500而不是404
我看到了关于这个问题的其他话题,但我找不到任何帮助我的东西
在终端:[02/Aug/2021 15:24:08] "GET /aaaaaaaaaaaa HTTP/1.1" 200 18285
AAAAA是获取404的随机url
目前没有回答
相关问题 更多 >
编程相关推荐