I read several posts about csrf protection in Django, including the Django documentation , but I'm still quite confused about how to use it correctly.
The brightest part is the HTML, but Python is somewhat confused.
HTML
{% csrf_token %} inside the form
Python
c = {} c.update(csrf(request))
You need this in every form when displaying and requesting information, right?
Then how to enable this csrf protection in return render() ? Is it correct?
return render(request,'index.html',{'var':var_value})
or include c somewhere, as in the Python documentation sample example ( return render_to_response("a_template.html", c) ). Or, if it is correct, is it included in request var?
And, when you do not need to use csrf, because I do not have any form. Will this be the correct form to return values ββto the template?
return render(request,'index.html',{'var':var_value})
anon
source share