当前位置: 首页>>代码示例>>Python>>正文


Python AuthenticationForm.add_error方法代码示例

本文整理汇总了Python中django.contrib.auth.forms.AuthenticationForm.add_error方法的典型用法代码示例。如果您正苦于以下问题:Python AuthenticationForm.add_error方法的具体用法?Python AuthenticationForm.add_error怎么用?Python AuthenticationForm.add_error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.auth.forms.AuthenticationForm的用法示例。


在下文中一共展示了AuthenticationForm.add_error方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: request_login

# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import add_error [as 别名]
def request_login(request):
    if request.POST:
        print "attempting login"
        form = AuthenticationForm(data=request.POST)
        if not form.is_valid():
            print "auth form is not valid"
            form.add_error(None, "Login failed")
            return render(request, "wishlist_app/login.html", {"login_form": form})
        "auth form is valid"
        username = request.POST['username']
        password = request.POST['password']
        print "authenticating %s" % username
        user = authenticate(username=username, password=password)
        login(request, user)
        return redirect("wishlists")
    else:
        form = AuthenticationForm()
        return render(request, "wishlist_app/login.html", {"login_form": form})
开发者ID:pclements12,项目名称:PyWishlist,代码行数:20,代码来源:operations.py

示例2: index

# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import add_error [as 别名]
def index(request):

    # are they logged in already? on to the incidents.
    if request.method == 'GET' and request.user.is_authenticated() and request.user.is_active:
        return redirect('/incidents')

    login_form = AuthenticationForm(data=request.POST or request.GET or None)
    if login_form.is_valid():
        username, password = login_form.cleaned_data['username'], login_form.cleaned_data['password']
        user = authenticate(username=username, password=password)
        if user is not None and user.is_active:
            last_login = user.last_login
            login(request, user)

            if not last_login:
                return redirect('change_password')
            else:
                return redirect('incident_list')
        else:
            login_form.add_error(None, "Your user is inactive.")

    # note -- may be returned in both GET and POST requests
    # (POST if their user/pass is invalid or inactive)
    return render(request, 'login.html', {'login_form': login_form})
开发者ID:Bernie-2016,项目名称:vincent,代码行数:26,代码来源:views.py


注:本文中的django.contrib.auth.forms.AuthenticationForm.add_error方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。