django - 无法理解 django csrf 豁免 cbv 的代码
问题描述
我无法理解调度方法的含义以及method_decorator是什么
class CSRFExemptMixin(object):
@method_decorator(csrf_exempt)
def dispatch(self, *args, **kwargs):
return super(CSRFExemptMixin, self).dispatch(*args, **kwargs)
你能回答这个问题吗?
解决方案
Dispatch 只是函数的名称。当某些东西将使用这个类时,这个函数将被触发。而method_decorator只是装饰器。装饰器是一个函数,它接收一个函数,在装饰器内部制作其他东西,然后最终执行接收到的函数。
推荐阅读
- arrays - 使过滤器与 Angular Material Data Table 中的 Array Object 属性一起正常工作
- azure - 无法从本地机器 ping 到 azure vnet
- azure - 阅读所有注册 azure notification hub python
- spring - 消息处理在 Spring 集成中随机暂停/暂停一小段时间
- javascript - 如何从一个html页面重定向到另一个html
- html - 使用属性在 HTML 中定位链接
- c++ - 非模板类中模板方法中的dll和静态变量
- elasticsearch - 字段总和的Elasticsearch(ELK堆栈)划分
- tomcat - 用 okhttp 3.81 看到很多 CLOSE_WAIT
- svn - 我可以 SVN 结帐到包含文件的目录吗?