跳至主要內容

视图-返回错误响应

刘春龙原创...小于 1 分钟PythonDjango教程文档

返回错误的 3 种方式:

  • 返回 HttpResponseNotFound
  • 返回 HttpResponse 设置 status 状态码
  • 返回 Http404 状态对象
from django.http import HttpResponse, Http404, HttpResponseNotFound

def loginFunc1(request, name):
    return HttpResponseNotFound("<h1>Page not found</h1>")

def loginFunc2(request):
    return HttpResponse(status=404)

def loginFunc3(request):
    raise Http404("Model does not exist")
上次编辑于:
贡献者: 刘春龙
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v2.15.7