Django请求类型的判断实现过滤

django.views.decorators.http

路由不能判断HTTP请求的类型

Django通过decorators在视图函数前进行基本判断,格式如下:

这段代码my_view实现只处理GET和POST方法,其他方法将被过滤掉

from django.views.decorators.http import require_http_methods

@require_http_methods(["GET","POST"])
def my_view(request):
    #我现在可以认为,只有GET或POST请求才能做到这一点
    #I can assume now that only GET or POST requests make it this far
    pass

 

posted @ 2024-02-29 17:07  十方劫  阅读(6)  评论(0编辑  收藏  举报