book/urls.py from django.urls import path from . import views urlpatterns = [ path('',views.IndexView.as_view(),name="index"), ] book/views.py from django.views import View from django.shortcuts import render class IndexView(View): def get(self,r
HttpResponse(content,conent_type=None,status=None,charset=None,*args,**kwargst)
book/views.py def index(request): http_list = { '
1.选择支持的请求方式 from django.views.decorators.http import require_http_methods from django.shortcuts import render @require_http_methods(['GET','POST']) def index(request): return render(request,"search.html") 2.只允许GET方法 require_GET() 3.只允许POST方法 require_PO
render(<request>,<template_name>,context=-None,content_type=None,status=None,using=None)
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 . import views from django.conf.urls import handler404 app_name
反爬虫: 1、我在django-views中设置了登录身份验证,设置了装饰器,通过META.get获取请求头,限制请求头和访问间隔。