加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

django-Views之常见的几种错误视图代码(三)

发布时间:2020-12-15 17:07:11 所属栏目:大数据 来源:网络整理
导读:1.404 page not found(找不到对应的页面) 2.500 server error(服务器错误) 3.400 bad request(无效的请求) 4.403 HTTP forbidden(HTTP禁止访问,权限不足) 5.200 OK (请求成功) 重新定义404模板: book/urls.py from django.urls import path from

1.404 page not found(找不到对应的页面)

2.500 server error(服务器错误)

3.400 bad request(无效的请求)

4.403 HTTP forbidden(HTTP禁止访问,权限不足)

5.200 OK (请求成功)

重新定义404模板:
book/urls.py

from django.urls import path
from .  views
from django.conf.urls  handler404
app_name ="book"
urlpatterns = [
    path('',views.index,name=index),]
handler404=views.page_not_found

book/views.py

from django.http  HttpResponse
from django.shortcuts  render,redirect,reverse
 resolve

# Create your views here.
def index(request):
    return HttpResponse(welcome)
def page_not_found(request,exception=404):
    return render(request,template_name=404.html")

settings.py

DEBUG = False

ALLOWED_HOSTS = [*"]

404.html

<!DOCTYPE html>
<html lang=en">
<head>
    <meta charset=UTF-8">
    <title>Title</title>
</head>
<body>
    <h1>好像出了点问题,界面消失了</h1>
</body>
</html>

?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读