"IntegrityError at authhentication/signup" даже после успешной регистрации

models.py

здесь я создал модель, необходимую каждому пользователю для регистрации

from django.db import models

# Create your models here.


class Details(models.Model):
    username = models.CharField(max_length=100)
    fname = models.CharField(max_length=100)
    lname = models.CharField(max_length=100)
    email = models.EmailField()
    password = models.IntegerField()
    confirm_password = models.IntegerField()

    def __str__(self):

        return f"{self.fname} {self.lname}"

views.py

здесь я определил свои представления для регистрации и входа

from django.shortcuts import render,redirect
from .models import Details
from  django.contrib import messages
from django.contrib.auth import authenticate,login

# Create your views here.

просмотр подписки

def signup(request):

    if request.method == "POST":
        username = request.POST.get("username")
        fname = request.POST.get("fname")
        lname = request.POST.get("lname")
        email = request.POST.get("email")
        password = request.POST.get("password")
        password2 = request.POST.get("password2")

        user = Details.objects.create(username=username,fname=fname,lname=lname,email=email,password=password,confirm_password=password2)

        messages.success(request,"Your account has been successfully created!")
        return render(request,'authentication/signin.html',)

         
    return render(request,'authentication/signup.html')

просмотр входа

def signin(request):
    
    if request.method == "POST":
        username = request.POST.get("username")
        password = request.POST.get("password")

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

        if user is not None:
            login(request, user)
            messages.success(request, "You have successfully logged in")
            name = Details.fname
            return render(request,'home.html',{'name':name})

        else:
            messages.error(request,"Bad credentials!")
            return redirect('authentication:signin')

    return render(request,'authentication/signin.html')


def signout(request):

    pass

signin.html

Здесь я создал свою форму входа

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <h1>Sign in here</h1>

    {% for message in messages %}
    <div class="alert alert-{{message.tags}} alert-dismissible fade show" role="alert">
    <strong>Message:</strong> {{message}}
    <button type="button" class="close" data-dismissible="alert" aria-label="close">
    <span aria-hidden="True">&times;</span>
    </button>
    </div>
    {% endfor %}<br><br>
    


<form action="" method="POST">
{% csrf_token %}

<label for="username">Username:</label>
<input type="text" id="username" name="username">

<label for="password">Password:</label>
<input type="password" id="password" name="password">

<input type="submit" >

</form>


   </body>
</html>

signup.html

Здесь я создал свою форму подписки

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>

    <h1>Sign up here</h1>


{% comment "" %}
    {% for message in messages %}
    <div class="alert alert-{{message.tags}} alert-dismissible fade show" role="alert">
    <strong>Message:</strong> {{message}}
    <button type="button" class="close" data-dismissible="alert" aria-label="close">
    <span aria-hidden="True">&times;</span>
    </button>
    </div>
    {% endfor %}
{% endcomment %}


<form action="" method="POST">
{% csrf_token %}

<label for="username">Username:</label>
<input type="text" id="username" name="username">

<label for="fname">First name:</label>
<input type="text" id="fname" name="fname">

<label for="lname">Last name:</label>
<input type="text" id="lname" name="lname">

<label for="email">E-mail:</label>
<input type="email" id="email" name="email">

<label for="password">Password:</label>
<input type="password" id="password" name="password">

<label for="password2">Confirm password:</label>
<input type="password" id="password2" name="password2">

<input type="submit">

</form> 


</body>
</html>

Пожалуйста, будьте добры, помогите мне разобраться, откуда берется IntegrityError.

Вернуться на верх