docs: def login(request, template_name=None,
            redirect_field_name=REDIRECT_FIELD_NAME,
            authentication_form=AuthenticationForm,
            current_app=None, extra_context=None):
      """
      Displays the login form and handles the login action.
      """
      redirect_to = request.POST.get(
          redirect_field_name,
          request.GET.get(redirect_field_name, '')
      )
  
      def get_redirect_to():
          # Ensure the user-originating redirection url is safe.
          if not is_safe_url(url=redirect_to, host=request.get_host()):
              return resolve_url(settings.LOGIN_REDIRECT_URL)
          return redirect_to
  
      if request.user.is_authenticated:
          return HttpResponseRedirect(get_redirect_to())
  
      if request.method == "POST":
          form = authentication_form(request=request, data=request.POST)
          if form.is_valid():
  
              # Okay, security check complete. Log the user in.
              auth_login(request, form.get_user())
  
              return HttpResponseRedirect(get_redirect_to())
      else:
          form = authentication_form(request=request)
  
      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)
  
      if current_app is not None:
          request.current_app = current_app
  
      return TemplateResponse(request, template_name, context)