I am trying to request.user for a form’s clean method, but how can I access the request object? Can I modify the clean method to allow variables input?
Share
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.
The answer by Ber – storing it in threadlocals – is a very bad idea. There’s absolutely no reason to do it this way.
A much better way is to override the form’s
__init__method to take an extra keyword argument,request. This stores the request in the form, where it’s required, and from where you can access it in your clean method.and in your view: