django-Views之装饰器(四)

时间:2022-07-23
本文章向大家介绍django-Views之装饰器(四),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

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_POST()

4.只允许get和head方法

require_safe()