@sensitive_post_parameters()
@csrf_protect
@never_cache
def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME, authentication_form=AuthenticationForm, current_app=None, extra_context=None):
 redirect_to = request.REQUEST.get(redirect_field_name, '')
 if (request.method == 'POST'):
  form = authentication_form(data=request.POST)
  if form.is_valid():
   if (not is_safe_url(url=redirect_to, host=request.get_host())):
    redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL)
   auth_login(request, form.get_user())
   if request.session.test_cookie_worked():
    request.session.delete_test_cookie()
   return HttpResponseRedirect(redirect_to)
 else:
  form = authentication_form(request)
 request.session.set_test_cookie()
 current_site = get_current_site(request)
 context = {'form': form, redirect_field_name: redirect_to, 'site': current_site, 'site_name': current_site.name}
 if (extra_context is not None):
  context.update(extra_context)
 return TemplateResponse(request, template_name, context, current_app=current_app)

@ sensitive_post_parameters ( ) @ csrf_protect @ never_cache def login ( request , template_name = 'registration/login.html' , redirect_field_name = REDIRECT_FIELD_NAME , authentication_form = AuthenticationForm , current_app = None , extra_context = None ) : redirect_to = request . REQUEST . get ( redirect_field_name , '' ) if ( request . method == 'POST' ) : form = authentication_form ( data = request . POST ) if form . is_valid ( ) : if ( not is_safe_url ( url = redirect_to , host = request . get_host ( ) ) ) : redirect_to = resolve_url ( settings . LOGIN_REDIRECT_URL ) auth_login ( request , form . get_user ( ) ) if request . session . test_cookie_worked ( ) : request . session . delete_test_cookie ( ) return HttpResponseRedirect ( redirect_to ) else : form = authentication_form ( request ) request . session . set_test_cookie ( ) current_site = get_current_site ( request ) context = { 'form' : form , redirect_field_name : redirect_to , 'site' : current_site , 'site_name' : current_site . name } if ( extra_context is not None ) : context . update ( extra_context ) return TemplateResponse ( request , template_name , context , current_app = current_app )
persist a user id and a backend in the request .