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
Source:stackexchange.com