[英]Django DetailView - how to use 'request' in get_context_data
I am trying to modify context data, so I overrided get_context_data
. 我正在尝试修改上下文数据,所以我重写了
get_context_data
。 I need the request
variable to modify this context. 我需要
request
变量来修改这个上下文。 So how can I get the request
variable in get_context-data
? 那么如何在
get_context-data
获取request
变量?
You have access to the request in self.request
- the third paragraph here explains a little more. 您可以访问
self.request
的请求 - 这里的第三段解释了一些。
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.
以及请求(self.request),这包括根据URLconf捕获的位置(self.args)和基于名称(self.kwargs)的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.