Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django login page

from django.contrib.auth import authenticate, login
fro django.shortcuts import render, redirect

def login_view(request):
    username = request.POST['username']
    password = request.POST['password']
    user = authenticate(request, username=username, password=password)
    if user is not None:
        login(request, user)
        # Redirect to a success page.
        return redirect('/')
        ...
    else:
        # Return an 'invalid login' error message.
        ...
        context = {'error':'Invalid username or password.'}
        return render(request, '/login.html', context)
        
               
Comment

django loginview?


#loginView
from django.contrib.auth.views import LoginView    

class AdminLogin(LoginView):
    template_name = 'LoginView_form.html'

Comment

django login

def login_view(request):
    if request.method == 'GET':
        cache.set('next', request.GET.get('next', None))

    if request.method == 'POST':
        # do your checks here

        login(request, user)

        next_url = cache.get('next')
        if next_url:
            cache.delete('next')
            return HttpResponseRedirect(next_url)

    return render(request, 'account/login.html')
Comment

django loginview

class Login(LoginView):
    template_name = "registration/login.html"
    def get_context_data(self, **kwargs):
        context = super(Login,self).get_context_data(**kwargs)
        page_title = 'Login'
        context.update({
            "page_title":page_title
         })
        return context
Comment

login view django

from django.contrib import messages
from django.contrib.auth import authenticate
from django.contrib.auth.forms import AuthenticationForm
from django.shortcuts import render, redirect

def login_view(request):
    if request.method == "POST":
        form = AuthenticationForm(request, data=request.POST)
        if form.is_valid():
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password')
            user = authenticate(username=username, password= password)
            if user is not None:
                login(request, user)
                messages.info(request, f"You are now logged in as {username}.")
                return redirect ('inventory:home')
            else:
                messages.error(request, "Invalid username or password")
    else:
        messages.error(request, "Invalid username or password")
    form = AuthenticationForm()
    return render(request, 'registration/login.html', context={"login_form":form})
Comment

PREVIOUS NEXT
Code Example
Python :: count elements in list 
Python :: python how to draw a square 
Python :: socket io python 
Python :: arrange array in ascending order python 
Python :: how to change size of turtle in python 
Python :: pandas pass two columns to function 
Python :: python sort columns of pandas dataframe 
Python :: Origin in CORS_ORIGIN_WHITELIST is missing scheme or netloc 
Python :: np.percentile 
Python :: python timedelta to seconds 
Python :: count number of each item in list python 
Python :: how to send file using socket in python 
Python :: urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:997) 
Python :: python copy 
Python :: pdf to csv python 
Python :: python check if key exists 
Python :: heroku python buildpack 
Python :: python how to count all elements in a list 
Python :: find index of values greater than python 
Python :: on progress callback pytube 
Python :: excel write in row 
Python :: python lambda 
Python :: python get the length of a list 
Python :: print out a name in python 
Python :: lerp function 
Python :: How to wait a page is loaded in Python Selenium 
Python :: how to make a multiple choice quiz in python with tkinter 
Python :: pandas change dtype 
Python :: directory path with python argparse 
Python :: python list of dictionary unique 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =