I dont know why i receiving this error login() takes 1 positional argument but 2 were given, ive just follow this tutorial that after sign-up it will login automatic https://www.csestack.org/django-sign-up-registration-form/
def login(request):
if request.method == 'POST':
form = SignUpForm(request.POST)
if form.is_valid():
print("test")
user = form.save()
user.refresh_from_db()
user.first_name = form.cleaned_data.get('first_name')
user.last_name = form.cleaned_data.get('last_name')
user.contact_number = form.cleaned_data.get('contact_number')
user.email = form.cleaned_data.get('email')
user.save()
insert = Customer(
user=user,
first_name=user.first_name,
last_name=user.last_name,
contact_number=user.contact_number,
email=user.email
)
insert.save()
raw_password = form.cleaned_data.get('password1')
users = authenticate(username=user.username, password=raw_password)
login(request, users)
return redirect('Homepage')
else:
form = SignUpForm()
return render(request, 'mysite/login.html', {'form': form})
this is the traceback
Traceback (most recent call last): File "C:\Users\clair\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\exception.py", line 55, in inner response = get_response(request) File "C:\Users\clair\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Users\clair\OneDrive\Desktop\Thesis\mysite\myapp\views.py", line 36, in login login(request, users)
Exception Type: TypeError at /login/ Exception Value: login() takes 1 positional argument but 2 were given
CodePudding user response:
Your view function is called login()
– rename it to e.g. login_view
so it does not shadow the Django login()
function you've imported and are trying to call.
CodePudding user response:
when you define your function with the same name of the imported function login
you override it ... so you can't use it try to add _view
for any function view to not face this Problem again