开发者

Obtaining a RequestContext for a templatetag included on every page

I have a templatetag which generates a form, this therefore requires the 开发者_如何学C{% csrf_token %} for security, which in turn requires a RequestContext object instead of the standard Context object.

Now, the particular templatetag/form in question is included in the header of every page. Currently every page doesn't render_to_response with a RequestContext object.

Is there any way in which I can get around this issue without having to changing every view within the entire site to pass through the RequestContext?

Thanks in advance.


All though there may be some workarounds, the best practice is definitely to add the RequestContext everywhere. This has advantages for other middlewares as well.

But there is also a legacy method, that will be removed in Django 1.4 that does not require you to change all your views. I would recommend against it unless you don't have much option.

http://docs.djangoproject.com/en/dev/ref/contrib/csrf/#legacy-method

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜