zoukankan      html  css  js  c++  java
  • django用户验证模块核心

    from django.shortcuts import render
    from django import forms
    from django.http import HttpResponse, HttpResponseRedirect
    from django.contrib.auth import authenticate, login, logout
    
    
    # Create your views here.
    from django.contrib.auth.decorators import login_required
    
    @login_required
    def my_view(request):
        if request.method == 'GET':
            logout(request)
        return render(request, 'index.html', {'a':'haha'})
    
    class MyForm(forms.Form):
        username = forms.CharField(label='username:', max_length=20)
        password = forms.CharField(label='password:', widget=forms.PasswordInput())
    
    def loginx(request):
        if request.method == 'POST':
            uf = MyForm(request.POST)
            username = request.POST['username']
            password = request.POST['password']
            nextweb = request.GET['next']
            user = authenticate(username=username, password=password)
            if user is not None:
                login(request, user)
                if nextweb is not None:
                    return HttpResponseRedirect(nextweb)
        else:
            uf = MyForm()
        return  render(request, 'login.html', {'uf':uf})
    

     源代码

    骑着毛驴看日出
  • 相关阅读:
    unordered_set
    树的所有实现
    各类算法模板
    单链表全部实现(绝对史上最完整 附例题)
    求最长回文子串
    无重复的最长子串
    秋叶集
    1451. 重新排列句子中的单词
    152. 乘积最大子数组
    JVM总结的部分内容
  • 原文地址:https://www.cnblogs.com/linsir/p/4545987.html
Copyright © 2011-2022 走看看