Django: passing request.user to a form
So you need access to request.user in your form for some reason, but you can’t just pass random objects to forms, and only the views have access to request. Here’s how it’s done:
Add an __init__() function to the form which looks like this:
Then, when you call the form from the view, add a new user parameter, so it looks like this:
Now you can access self.user anywhere in the form.