Django's authentication form is always not valid -
i trying implement basic login system using django custom user using abstractuser class. here models.py:
from django.db import models django.contrib.auth.models import abstractuser class stock(models.model): stock_name = models.charfield(max_length=10) stock_price = models.floatfield() def __str__(self): return self.stock_name class customuser(abstractuser): stocks = models.manytomanyfield(stock) def __str__(self): return self.username
my forms.py:
from .models import customuser,stock django.contrib.auth.forms import authenticationform class loginform(authenticationform): class meta: model = customuser fields = ('username', 'password')
my views.py:
def successful_login(request, pk): user = get_object_or_404(customuser, pk=pk) return render(request, '../templates/stock_portfolio.html',{'user':user}) def loginview(request): err=0 if request.method=="post": form = loginform(request.post) pdb.set_trace() if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] user = authenticate(username=username, password=password) if user not none: pdb.set_trace() login(request, user) pk = user.id pdb.set_trace() return redirect('successful_login', pk=pk) else: err=1 return render(request,'../templates/login.html',{'response':err,'form':form}) else: form = loginform() return render(request, '../templates/login.html',{'form':form})
while logging using pdb here getting form.
<loginform bound=false, valid=unknown, fields=(username;password)>
how proceed now?
wiki
Comments
Post a Comment