Problem withLogin in Django

18 views
Skip to first unread message

IT Technology bySaikiran

unread,
Nov 13, 2019, 9:42:37 AM11/13/19
to Django users
Views.py:
=========
def login(request):
if request.method == 'POST':
username = request.POST['username']
password = request.POST['Password1']
for i in register.objects.all():
print('db Value'+i.username)
if i.username == 'saikiran_maddipatla' and i.password == '1919':
print('Success')
print('Value not matched')
print(username)
print(password)
user = auth.authenticate(username= username, password= password)
print(user)
if user is not None:
print('Login Success')
auth.login(request, user)
return render(register)
else:
print("failed")
return redirect('login')


else:
return render(request, 'web_app/login.html')

Models.py:
=============

from django.db import models


# Create your models here.
class register(models.Model):
username=models.CharField(max_length=100)
password=models.CharField(max_length=100)
email=models.CharField(max_length=100)
fname=models.CharField(max_length=30)
lname=models.CharField(max_length=30)
user_regdate=models.DateTimeField()

def __str__(self):
return self.username


i am trying to login,User return None 
Please help me on this.

Kasper Laudrup

unread,
Nov 13, 2019, 11:34:48 AM11/13/19
to Django users, IT Technology bySaikiran


"IT Technology bySaikiran" <saikiran.ma...@gmail.com> – 13. november 2019 15:41
> Views.py:=========def login(request):
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4191b3c9-ac79-452a-9230-d74558d1901b%40googlegroups.com
> .

Kasper Laudrup

unread,
Nov 13, 2019, 11:35:59 AM11/13/19
to Django users, IT Technology bySaikiran
Hi Saikiran,

On 13/11/2019 15.07, IT Technology bySaikiran wrote:
>
> # Create your models here.
> class register(models.Model):
> username=models.CharField(max_length=100)
> password=models.CharField(max_length=100)
> email=models.CharField(max_length=100)
> fname=models.CharField(max_length=30)
> lname=models.CharField(max_length=30)
> user_regdate=models.DateTimeField()
>
You haven't provided any details on what you want to achieve, but it looks like you're trying to implement your own authentication system storing passwords in cleartext.

That's a horrible idea and probably the reason why you cannot make it work with Djangos authentication model.

What exactly are you trying to achieve that cannot be done with the standard Django authentication model?

Maybe look into customizing the user model:

https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html

Kind regards,

Kasper Laudrup

Reply all
Reply to author
Forward
0 new messages