Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

django login code

from django.contrib.auth import authenticate, login

def my_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.
        ...
    else:
        # Return an 'invalid login' error message.
        ...
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

login system in django

LOGOUT_REDIRECT_URL = 'your_url'
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 :: python how to loop 
Python :: python3 
Python :: sys.argv python example 
Python :: indefinite loops python 
Python :: python click activator 
Python :: Sound alerts in Jupyter for code completion and exceptions 
Python :: full body tracking module 
Python :: InsertionSort 
Python :: python list of deeper paths 
Python :: Search for a symmetrical inner elements of a list python 
Python :: python programming online editor 
Python :: django snippet 800 
Python :: imagefont cannot open resource 
Python :: wails get started 
Python :: b-spline quantile regression with statsmodels 
Python :: function palindrome python 
Python :: matplotlib smooth loss curves 
Python :: how to add extra str in python?phython,add,append,insert 
Python :: text file sort by first item in each row 
Python :: plotly change marker symboly sequence 
Python :: how to build a compiler in python 
Python :: separate alphanumeric list 
Python :: network setting for virtualbox kali 
Python :: add label on choropleth map python 
Python :: python scrapy 
Python :: how to crack a 4 way handshake with python 
Python :: how to create a leaderboard on python 3.8.1 
Python :: Logistic Regression with a Neural Network mindset python example 
Python :: return a tuple c++ python 3 
Python :: get attribute of timestamp python 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =