BaseForm.__init__() got an unexpected keyword argument 'my_username'

once i made a simple login form in django i got this error

i searched a lot but i found nothing i read many articles here and github enter image description here

this is my form code and views code.

i made it with html it worked but in django project i created file named it form.py

wrote the code once trying to run server got this error

i tried searching in the documention of django

can any one help please

You don't pass data as named parameters to the form, you pass it as a dictionary-like object. In fact request.POST (and request.GET), etc. are already dictionary-like objects:

def my_login(request):
    user_data = LoginPage(request.POST, request.FILES)
    # …

But you can not use user_data.save(): you use a Form, not a ModelForm, so it has no .save() method. You can check if the user_data.is_valid(), and if so, access user_data.cleaned_data['my_username] to obtain the data entered for that field.


Note: Functions are normally written in snake_case, not PascalCase, therefore it is advisable to rename your function to my_login, not myLogin.


Note: Usually a Form or a ModelForm ends with a …Form suffix, to avoid collisions with the name of the model, and to make it clear that we are working with a form. Therefore it might be better to use LoginPageForm instead of Login_Page.

Back to Top