Why u create registration model for authentication because authentication
model already included when u run command make migrations.
U only import django.contrib.auth import User, authenticate and use

On Sun, Jul 30, 2023, 7:02 AM Mh Limon <mhlimon...@gmail.com> wrote:

> This is my views.py code. when providing the correct username and
> password, the system consistently displays an error message stating "You
> have incorrect Username or password."
> from django.shortcuts import render,HttpResponse,redirect
> from .models import registration
> from django.contrib.auth import authenticate,login
>
> def home(request):
>     return render(request,'home.html')
>
> def log_in(request):
>     if request.method == 'POST':
>         username = request.POST.get('username')
>         password = request.POST.get('password')
>
>         user = authenticate(request, username=username, password=password)
>
>         if user is not None:
>             login(request, user)
>             return redirect('home')
>         else:
>             return HttpResponse("You have incorrect Username or password")
>
>     return render(request, 'log_in.html')
>
>
> def sign_up(request):
>     if request.method == 'POST':
>         name = request.POST.get('fullname')
>         username = request.POST.get('username')
>         email = request.POST.get('email')
>         pass1 = request.POST.get('password')
>         pass2 = request.POST.get('confirm_password')
>
>         if pass1 != pass2:
>             return HttpResponse("Password not matched")
>         else:
>             db = registration()
>
>             db.Name = name
>             db.username = username
>             db.Email = email
>             db.Password = pass1
>
>             db.save()
>
>             return redirect('log_in')
>
>
>     return render(request,'sign_up.html')
>
> This is models.py for SQLite database:
> from django.db import models
>
> class registration(models.Model):
>     Name = models.CharField(max_length=100)
>     username = models.CharField(max_length=100)
>     Email = models.CharField(max_length=100)
>     Password = models.CharField(max_length=100)
>
> Please help me for solve this problem
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/d6c32ddf-746b-43a8-87dc-2ab27721c107n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/d6c32ddf-746b-43a8-87dc-2ab27721c107n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAAr4ktSzS6rudsee_4MpUQucXCT9%2Brn2XW%3DpxSUtWnhaupgS4Q%40mail.gmail.com.

Reply via email to