相关疑难解决方法(0)

Django,自定义身份验证登录.身份验证失败时如何显示错误消息?

我正在创建自定义身份验证登录.除了在电子邮件和密码不正确时显示错误消息外,一切似乎都有效.

我知道这与登录失败时我对login.html页面的呈现有关,而且没有提供表单,因为尝试登录失败这一事实,但我不知道如何将其放入我的代码.

views.py

from django.shortcuts import render_to_response
from django.contrib.auth.decorators import login_required
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.contrib.auth import authenticate, login, logout
from django.http import HttpResponseRedirect

def login_user(request):

logout(request) #logs out user upon reaching the /login/ page

email = password = ''
if request.POST:
    email = request.POST['email']
    password = request.POST['password']

    user = authenticate(email=email, password=password)
    if user is not None:
        if user.is_active:
            login(request, user)
            return HttpResponseRedirect('/successful_login/')
        else:
           state = "Your account is not active, please contact the administrator." …
Run Code Online (Sandbox Code Playgroud)

forms authentication django

2
推荐指数
1
解决办法
4297
查看次数

标签 统计

authentication ×1

django ×1

forms ×1