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


Python AuthenticationForm.get_validation_errors方法代码示例

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


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

示例1: login

# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import get_validation_errors [as 别名]
def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME):
    "Displays the login form and handles the login action."
    manipulator = AuthenticationForm()
    redirect_to = request.REQUEST.get(redirect_field_name, '')
    if request.POST:
        errors = manipulator.get_validation_errors(request.POST)
        if not errors:
            # Light security check -- make sure redirect_to isn't garbage.
            if not redirect_to or '//' in redirect_to or ' ' in redirect_to:
                from django.conf import settings
                redirect_to = settings.LOGIN_REDIRECT_URL
            from django.contrib.auth import login
            login(request, manipulator.get_user())
            if request.session.test_cookie_worked():
                request.session.delete_test_cookie()
            return HttpResponseRedirect(redirect_to)
    else:
        errors = {}
    request.session.set_test_cookie()

    if Site._meta.installed:
        current_site = Site.objects.get_current()
    else:
        current_site = RequestSite(request)

    return render_to_response(template_name, {
        'form': oldforms.FormWrapper(manipulator, request.POST, errors),
        redirect_field_name: redirect_to,
        'site_name': current_site.name,
    }, context_instance=RequestContext(request))
开发者ID:hfeeki,项目名称:geodjango,代码行数:32,代码来源:views.py

示例2: login

# 需要导入模块: from django.contrib.auth.forms import AuthenticationForm [as 别名]
# 或者: from django.contrib.auth.forms.AuthenticationForm import get_validation_errors [as 别名]
def login(request, template_name='registration/login.html'):
    "Displays the login form and handles the login action."
    manipulator = AuthenticationForm(request)
    redirect_to = request.REQUEST.get(REDIRECT_FIELD_NAME, '')
    if request.POST:
        errors = manipulator.get_validation_errors(request.POST)
        if not errors:
            # Light security check -- make sure redirect_to isn't garbage.
            if not redirect_to or '://' in redirect_to or ' ' in redirect_to:
                redirect_to = '/accounts/profile/'
            from django.contrib.auth import login
            login(request, manipulator.get_user())
            request.session.delete_test_cookie()
            return HttpResponseRedirect(redirect_to)
    else:
        errors = {}
    request.session.set_test_cookie()
    return render_to_response(template_name, {
        'form': oldforms.FormWrapper(manipulator, request.POST, errors),
        REDIRECT_FIELD_NAME: redirect_to,
        'site_name': Site.objects.get_current().name,
    }, context_instance=RequestContext(request))
开发者ID:0xmilk,项目名称:appscale,代码行数:24,代码来源:views.py


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