论坛首页 入门技术论坛

Django自带的用户验证

浏览 1103 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2014-01-23  

用户自带验证的功能,其实挺不错的,首先在settings.py里面加入其应用

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.request",
)

 

在homepage.py

from django import forms
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from django.contrib.auth.models import User
from django.contrib.auth import authenticate, login as user_login, logout as user_logout
from django.template import loader, Context, Template
from django.shortcuts import render_to_response
import simplejson as json

def homepage(req):
    user = authenticate(username='linkedin', password='i123312')
    if user is not None:
            if user.is_active:
                print 'user is active'
            else:
                print 'user is not active'
    else:
        print 'user is not exit'
    t = loader.get_template('home.html')
    c = Context({})

    return HttpResponse(t.render(c))

 

论坛首页 入门技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics