Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23247

django login Authentication returns None

$
0
0

I am trying to authenticate in django but when I enter the real credentials it assigns the user as None, but when I enter credentials that do not exist it does not assign it as None.

views.py

def login_view(request):    if request.method == 'POST':        form = LoginForm(data=request.POST)        if form.is_valid():            usuario = form.cleaned_data.get('usuario')            contraseña = form.cleaned_data.get('contraseña')            print(usuario, contraseña)            user = authenticate(request, username=usuario, password=contraseña)            print(user)            if user is not None:                login(request, user)                return JsonResponse({'success': True, 'message': 'Usuario o contraseña Correcta.'})            else:                return JsonResponse({'success': False, 'message': 'Usuario o contraseña falsa.'})    else:        form = LoginForm()    return render(request, 'login.html', {'form': form})

forms.py

class LoginForm(forms.Form):    usuario = forms.CharField()    contraseña = forms.CharField(widget=forms.PasswordInput)    def clean(self):        cleaned_data = super().clean()        usuario = cleaned_data.get('usuario')        contraseña = cleaned_data.get('contraseña')        if not Usuario.objects.filter(usuario=usuario, contraseña=contraseña).exists():            self.add_error('usuario', 'Usuario o contraseña incorrectos.')        return cleaned_data

When I enter real data this is how the terminal looks like

LoginCredecialthe 1 1 is a print of (usuario, contraseña)

and when i enter fake data this is how the terminal looks like

FakeCredentials

I have tried to modify the views but have not achieved any results to date.


Viewing all articles
Browse latest Browse all 23247

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>