django DetailView - 如何在get_context_data中使用'request' [英] django DetailView - how to use 'request' in get_context_data

查看:489
本文介绍了django DetailView - 如何在get_context_data中使用'request'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试修改上下文数据,所以我覆盖了get_context_data。我需要'request'变量来修改这个上下文。那么,如何在get_context-data中获取'request'变量?

解决方案

你可以访问 self.request - 第三段这里再说一遍。



编辑:文字被提到,万一它改变了:



这个工作的关键部分是当基于类的视图被调用时,各种有用的东西被存储在自;以及请求(self.request),它包括根据URLconf捕获的位置(self.args)和基于名称的(self.kwargs)参数。




I am trying to modify context data, so I overrided get_context_data. I need 'request' variable for modify this context. So, how can i get 'request' variable in get_context-data ?

解决方案

You have access to the request in self.request - the third paragraph here explains a little more.

EDIT: The text referred to, in case it changes:

The key part to making this work is that when class-based views are called, various useful things are stored on self; as well as the request (self.request) this includes the positional (self.args) and name-based (self.kwargs) arguments captured according to the URLconf.

这篇关于django DetailView - 如何在get_context_data中使用'request'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆