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

How do I do a Django authorization data check?

$
0
0

So, I wrote the code for the reg.html page. If the registration data is filled in correctly, the form is saved and the account is created. I checked everything, the data is entered into the database. The only thing left to do is to make authorization. But here's the question - how do you do a check for the correct data? To put it simply, if the user logs in and such an account actually exists, then it should be redirected to the main page. Otherwise, the site will display "There is no such account". Here is the code below.

views.py:

from django.shortcuts import render, redirectfrom django.http import HttpResponsefrom .form import SignUpForm, RegisterFormfrom .models import Registrationdef index(request):    return render(request, 'main/index.html',)def about(request):    return render(request, 'main/about.html')def register(request):    if request.method == 'POST':        form = RegisterForm(request.POST)        if form.is_valid():            form.save(commit=False)            return redirect('log')    form = RegisterForm()    return render(request, 'main/reg.html', {'form': form    })def log(request):    if request.method == "POST":        form = SignUpForm(request.POST)        if form.is_valid():             if Registration().objects.filter().exists():                return HttpResponse('Да')            else:                return HttpResponse('Нет')    form = SignUpForm()    return render(request, 'main/log.html', {'form': form    })

Viewing all articles
Browse latest Browse all 23131

Trending Articles



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