Skip to content Skip to sidebar Skip to footer

Clarification On The Statement If Request.post: In Django

Suppose I have a view like this: def home(request, redir_url, template = 'example/home.html') if request.session['profile_name'] and request.session['token']: retu

Solution 1:

It should be

if request.method == 'POST'

This sentence is executed every time you access the url configured for this view. If the method of the request was POST, when the user presses the button, then the code inside if is executed and a HttpResponse is returned

In the example the line render(request, template) is only executed when the method was'nt POST (maybe GET, PUT, DELETE, etc).

Finally, you could use Django Login Decorator to avoid the session variables checking

Post a Comment for "Clarification On The Statement If Request.post: In Django"