Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django DetailView - how to use 'request' in get_context_data

Tags:

python

django

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?

like image 400
user2139745 Avatar asked Apr 26 '13 19:04

user2139745


People also ask

How do I see requests in Django?

It's possible that a request can come in via POST with an empty POST dictionary -- if, say, a form is requested via the POST HTTP method but does not include form data. Therefore, you shouldn't use if request. POST to check for use of the POST method; instead, use if request. method == "POST" (see above).

What is request POST get in Django?

When a POST request is received at the Django server, the data in the request can be retrieved using the HTTPRequest. POST dictionary. All the data of the POST request body is stored in this dictionary. For example, you can use the following code snippet inside your view.py file.


1 Answers

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.

like image 156
girasquid Avatar answered Sep 23 '22 06:09

girasquid