Django开发者群  - 讨论区

标题:CsrfResponseMiddleware和csrf_token实现的功能一样吗?

2012年03月03日 星期六 07:08

CsrfResponseMiddleware和csrf_token实现的功能一样吗?

2012年03月03日 星期六 17:52

需要配合起来使用。CsrfResponseMiddleware是middleware,csrf_token是templatetag(用在模板中)。

可以看django文档:

https://docs.djangoproject.com/en/dev/ref/contrib/csrf/

2012年03月03日 星期六 20:13

我就是看官网时有点不懂,“Use of the CsrfResponseMiddleware is not recommended because of the performance hit it imposes, and because of a potential security problem (see below). It can be used as an interim measure until applications have been updated to use the csrf_token tag. It is deprecated and will be removed in Django 1.4.”我看的意思好像是说:他们功能一样,但是csrf_token更好一点,所以要在django1.4中移除!

2012年03月03日 星期六 22:14

个人觉得,使用midleware是一种优雅的设计,不过副作用也比较明显。

最明显是性能问题。每次请求都需要经过midleware的检查,所以放到middleware的特性都应该是极其简单的。

至于过期的原因,估计django的设计者是觉得开发者需要更细力度的控制如何作csrf。

 

 

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2024

    京ICP备05028076号