用户自带验证的功能,其实挺不错的,首先在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))