I am trying to register new user from Django to PostgreSQL from the app which I created but it is not getting updated in database

I am trying to register new user from Django to PostgreSQL from the app which I created but it is not getting updated in database, but logs are getting generated in PostgreSQL for my each attempts from Django framework and the database table screenshot has been attached here.

I also noticed Django.contrib import error but I think it is not problem because rest all codes working fine like I am able to upload photos from admin panel and it is reflecting in my web portal and database as well.

..............................................

#accounts\views.py.

from django.shortcuts import render, redirect
from django.contrib import messages
from django.contrib.auth.models import User, auth

# Create your views here.

def login(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']

        user = auth.authenticate(username=username,password=password)

        if user is not None:
            auth.login(request, user)
            return redirect("/")
        else:
            messages.info(request,'invalid creds')
            return redirect('login')

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


def register(request):

    if request.method == 'POST':
        first_name = request.POST['first_name']
        last_name = request.POST['last_name']
        username = request.POST['username']
        password1 = request.POST['password1']
        password2 = request.POST['password2']
        email = request.POST['email']

        if password1==password2:
            if User.objects.filter(username=username).exists():
                messages.info(request,'Username Taken')
                return redirect('register')
            elif User.objects.filter(email=email).exists():
                messages.info(request,'Email taken')
                return redirect('register')
            else:
                user = User.objects.create_user(username=username,password=password1,email=email,first_name=first_name,last_name=last_name)
                user.save()
                messages.info(request,'User created')
                return redirect('login')


        else:
            messages.info(request,'Password not matching')
            return redirect('register')
        return redirect('/')

    else:
        return render(request,'register.html')


def logout(request):
    auth.logout(request)
    return redirect('/')



#[Postgres log when I submit new registration form][1]


  [1]: https://i.stack.imgur.com/b9q2E.png
Back to Top