Django DetailView - how to use 'request' in get_context_data

PythonDjango

Python Problem Overview


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

Python Solutions


Solution 1 - Python

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2139745View Question on Stackoverflow
Solution 1 - PythongirasquidView Answer on Stackoverflow