Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python - login

// 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>
Comment

login python code

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()    
Comment

PREVIOUS NEXT
Code Example
Python :: max value of a list prolog 
Python :: check if boolean is true python 
Python :: continue statement in python 
Python :: hexdigest python 
Python :: anonymous function python 
Python :: python poetry 
Python :: convert string to int python 
Python :: pandas fillna multiple columns 
Python :: sample hyperparameter tuning with grid search cv 
Python :: global var in python 
Python :: sum of even numbers 
Python :: python math packege power e 
Python :: field in django 
Python :: django password hashing 
Python :: is login a class in python 
Python :: python selenium driver 
Python :: List Get a Element 
Python :: telegram telethon get new user details 
Python :: python iterating through a list 
Python :: combine 3 jupyter cells together 
Python :: python create empty list size n 
Python :: google youtuve api 
Python :: drop pandas 
Python :: principal component analysis (pca) 
Python :: How To Remove Elements From a Set using remove() function in python 
Python :: how to remove some indexes from a dataframe in python 
Python :: what is self 
Python :: append to a tuple 
Python :: python using shutil method 
Python :: dot product of lists 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =