[Answered ]-Django How to pre-populate a form field with a argument form context

2👍

What you want to do is pass initial data to the form. Assuming that LoginView is a class-based view that includes the FormMixin, this is best done in the get_form_kwargs method:

def get_form_kwargs(self):
    kwargs = super(CampaignLoginView, self).get_form_kwargs()
    kwargs['initial']['email'] = self.request.user.email
    return kwargs

Leave a comment