// Paste then into views.py inside the APP folder
from django.shortcuts import render, redirect
from .models import Team
from cars.models import Car
from django.contrib import messages, auth
from django.contrib.auth.models import User
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)
messages.success(request, 'You are now logged in.')
return redirect('dashboard')
else:
messages.error(request, 'Invalid login credentials')
return redirect('login')
return render(request, 'pages/login.html')
// inside login.html
// Note: The ( type="") and ( name="" ) must in small letter
// Must be the same in database
{% include 'includes/messages.html' %}
<form action="{% url 'login'%}" method="POST">
{% csrf_token %}
<div class="form-group form-box">
<input type="text" name="username" class="input-text" placeholder="Username" required>
<i class="flaticon-mail"></i>
</div>
<div class="form-group form-box">
<input type="password" name="password" class="input-text" placeholder="Password" required>
<i class="flaticon-lock"></i>
</div>
<div class="form-group mb-0 clearfix">
<button type="submit" class="btn-md btn-theme float-left">Login</button>
</div>
<div class="extra-login clearfix">
<span>Or Login With</span>
</div>
<div class="clearfix"></div>
<ul class="social-list">
<li><a href="#" class="facebook-bg"><i class="fa fa-facebook facebook-i"></i><span>Facebook</span></a></li>
<li><a href="#" class="google-bg"><i class="fa fa-google google-i"></i><span>Google</span></a></li>
</ul>
</form>
username = input(' enter your username: ')
if username == 'Put Your Username Here':#change this
print("checking username")
time.sleep(0.5)
print("username is right")
password = input(' type your password: ')
if password == 'Put Your Password Here':#change this
time.sleep(0.5)
else:
exit()
else:
exit()