Rasik Rasik - 1 month ago 11
Python Question

TypeError at /home/register/ __init__() takes 1 positional argument but 3 were given

I m trying to register the user using a registration form.When I hit the register button the user gets registered but the redirection doesn't happen instead i m getting the error:

TypeError at /home/register/ __init__() takes 1 positional argument but 3 were given

views.py

class register(View):
form_class = UserForm
template_name = 'register.html'

def get(self, request):
form = self.form_class(None)
return render(request, self.template_name, {'form': form})

def post(self, request):
form = self.form_class(request.POST)

if form.is_valid():
user = form.save(commit=False)
username = form.cleaned_data['username']
password = form.cleaned_data['password']
user.set_password(password)
user.save()
auth_user = authenticate(username=username, password=password)

if auth_user is not None:

if auth_user.is_active:
login(request, auth_user)
return redirect('manager:home')

return render(request, self.template_name, {'form': form})


register.html

REGISTRATION
<form action="" method="POST">
{% csrf_token %}
{{form.as_p}}
<button type="sbumit">REGISTER</button>
</form>


urls.py

from django.conf.urls import include, url
from .views import register,home, contact, contactList, login, logout

app_name = 'manager'

urlpatterns = [
url(r'^$', home.as_view(), name='home'),
url(r'^contact/$', contact, name='contact'),
url(r'^list/$', contactList, name='list'),
url(r'^register/$', register.as_view() , name='register'),
url(r'^login/$', login.as_view() , name='login'),
url(r'^logout/$', logout , name='logout'),

]


link to the whole code: Github

Error

Answer

Your login view is shadowing Django's login function. You need to rename that view to something else, say LoginView