How to call a view in my layout (template) ?
For example : I’ve a form on every pages of my website. I need to generate CSRF token for each pages but I don’t want to put the generation code on every view.
Thank you.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In Django, once you reach the template, I don’t believe you can call something to the effect of Zend’s Action Helper.
Obviously, you could do an AJAX call to an exposed url in Django and retrieve the necessary data. In that case you can provide the csrf token to the ajax calls as follows..
I’m not a hundred percent sure but you can implement something like Zend’s Action Helper in a decorator (which could be applied to multiple views of your choice before processing the request) or in a context processor (which is applied to all views’ processed request).