Issue
this is my views.py
from django.shortcuts import render, redirect
from django.views.generic import TemplateView
from django.contrib.messages.views import SuccessMessageMixin
from django.views.generic.edit import CreateView
from django.urls import reverse_lazy
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login, logout
####################################################
class Main(TemplateView):
template_name = 'emnosys/main.html'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['css_file'] = 'styles.css'
return context
###################################################
def Registration(request):
if request.method == "POST":
username = request.POST['username']
email = request.POST['email']
password1 = request.POST['password1']
password2 = request.POST['password2']
myuser = User.objects.create_user(username, emnail, password1)
myuser.save()
return redirect('signin')
return render(request, "emnosys/registration.html")
###############################################
def signin(request):
if request.method == 'POST':
username = request.POST['username']
password1 = request.POST['pass1']
user = authenticate(username=username, password=password1)
if user is not None:
login(request, user)
return render(request, "authentication/index.html")
else:
return redirect('home')
return render(request, "emnosys/signin.html")
################################################
def signout(request):
logout(request)
return redirect('home')
This is my urls
from django.urls import path
from . import views
from .views import Main
urlpatterns = [
path('', Main.as_view(), name='home'),
path('registration/', views.Registration, name='registration'),
path('signin/', views.signin, name='signin'),
path('signout/', views.signout, name='signout'),
]
this is my registration.html
!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="../../static/emnosys/css/styles-registration.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="">
<div class="login">
<h3>Registration</h3>
<form action="/signup" method="post">
{% csrf_token %}
<label for="">Username</label>
<input type="text" id="username" name="username" placeholder="write username">
<br>
<label for="">Email</label>
<input type="text" id="email" name="username" placeholder="write email">
<br>
<label for="">Password</label>
<input type="text" id="password1" name="username" placeholder="write password">
<br>
<label for="">Confirm your password</label>
<input type="text" id="password2" name="username" placeholder="confirm your password">
<br>
<button type="sumbit">Sign Up</button>
</form>
</div>
<div class="waves">
<img src="../../static/emnosys/images/waves.png" alt="">
</div>
</form>
</body>
</html>
this is my login(signin).html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="../../static/emnosys/css/styles-login.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="">
<div class="login">
<h3>Login</h3>
<div class="username">
<input type="text" id="login" placeholder=" " autocomplete="off">
<label for="#login" id="label1">Username</label>
</div>
<div class="password">
<input type="password" id="password" placeholder=" " autocomplete="off">
<label for="#password" id="label2">Password</label>
</div>
<div class="foot">
<input type="checkbox" name="" id="remember-me">
<label for="#register-link">Remember me</label>
<a href="registration.html" id="register-link">Registration</a>
</div>
<div class="submit">
<button type="submit" id="submit--button">
Submit
</button>
</div>
</div>
<div class="waves">
<img src="../../static/emnosys/images/waves.png" alt="">
</div>
</form>
</body>
</html>
I write all data on registration page, press button,
After it i can see text in terminal
[07/Nov/2023 16:50:37] "GET /registration/?csrfmiddlewaretoken=eOYzmvnkKHCBC13PTvIKoUCegTcwTjw1danUrjGXWIqV nyy5tnnMNcX1Cw2N0QeS&username=parrot&username=parrot%40gmail.com&username=Qwe123&username=Qwe123 HTTP/1.1" 200 1495
And there is no new users in admin panel
I would be extremely grateful if someone could help
I expect that after writing data in registration.html and signin in login.html i will see new user in admin panel
Solution
inside registeration.html you use a from inside a form
so change your registeration.html:-
!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="../../static/emnosys/css/styles-registration.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="login">
<h3>Registration</h3>
<form action="" method="post">
{% csrf_token %}
<label for="">Username</label>
<input type="text" id="username" name="username" placeholder="write username">
<br>
<label for="">Email</label>
<input type="text" id="email" name="email" placeholder="write email">
<br>
<label for="">Password</label>
<input type="text" id="password1" name="password1" placeholder="write password">
<br>
<label for="">Confirm your password</label>
<input type="text" id="password2" name="password2" placeholder="confirm your password">
<br>
<button type="sumbit">Sign Up</button>
</form>
</div>
<div class="waves">
<img src="../../static/emnosys/images/waves.png" alt="">
</div>
</body>
</html>
and your login(signin).html :-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="../../static/emnosys/css/styles-login.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="" method="post">
{% csrf_token %}
<div class="login">
<h3>Login</h3>
<div class="username">
<input type="text" id="login" name="username" placeholder=" " autocomplete="off">
<label for="#login" id="label1">Username</label>
</div>
<div class="password">
<input type="password" id="password" name="pass1" placeholder=" " autocomplete="off">
<label for="#password" id="label2">Password</label>
</div>
<div class="foot">
<input type="checkbox" name="" id="remember-me">
<label for="#register-link">Remember me</label>
<a href="registration.html" id="register-link">Registration</a>
</div>
<div class="submit">
<button type="submit" id="submit--button">
Submit
</button>
</div>
</div>
<div class="waves">
<img src="../../static/emnosys/images/waves.png" alt="">
</div>
</form>
</body>
</html>
Answered By - BiswajitPaloi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.