Derek Stegelman

Snippet Sunday: Access the Request Object Inside a Django Form

#Form
class MyForm(forms.Form):

    def __init__(self, *args, **kwargs):
        self.request = kwargs.pop('request', None)
        super(MyForm, self).__init__(*args, **kwargs)


        def clean(self):
        #... access the request object via self.request ...
        #and in your view:


# Inside the view
myform = MyForm(request.POST, request=request)