码迷,mamicode.com
首页 > 其他好文 > 详细

django用户验证模块核心

时间:2015-06-02 12:47:53      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

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})

 

 源代码

django用户验证模块核心

标签:

原文地址:http://www.cnblogs.com/linsir/p/4545987.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!