admin.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:texta 作者: texta-tk 项目源码 文件源码
def login(self, request, extra_context=None):
    """
    Displays the login form for the given HttpRequest.
    """
    if request.method == 'GET' and self.has_permission(request):
        # Already logged-in, redirect to admin index
        index_path = reverse('admin:index', current_app=self.name)
        return HttpResponseRedirect(URL_PREFIX_RESOURCE+index_path)

    from django.contrib.auth.views import login
    # Since this module gets imported in the application's root package,
    # it cannot import models from other applications at the module level,
    # and django.contrib.admin.forms eventually imports User.
    from django.contrib.admin.forms import AdminAuthenticationForm
    context = dict(self.each_context(request),
        title= ('Log in'),
        app_path=request.get_full_path(),
    )
    if REDIRECT_FIELD_NAME not in request.GET and REDIRECT_FIELD_NAME not in request.POST:
        context[REDIRECT_FIELD_NAME] = request.get_full_path()
    context.update(extra_context or {})

    defaults = {
        'extra_context': context,
        'current_app': self.name,
        'authentication_form': self.login_form or AdminAuthenticationForm,
        'template_name': self.login_template or 'admin/login.html',
    }
    return login(request, **defaults)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号