@sensitive_post_parameters()<EOL>@csrf_protect<EOL>@never_cache<EOL>def login(request, template_name='<STR_LIT>',<EOL>redirect_field_name=REDIRECT_FIELD_NAME,<EOL>authentication_form=AuthenticationForm,<EOL>current_app=None, extra_context=None):
redirect_to = request.POST.get(redirect_field_name,<EOL>request.GET.get(redirect_field_name, '<STR_LIT>'))<EOL>if request.method == "<STR_LIT:POST>":<EOL><INDENT>form = authentication_form(data=request.POST, request=request)<EOL>if form.is_valid():<EOL><INDENT>netloc = urlparse(redirect_to)[<NUM_LIT:1>]<EOL>if not redirect_to:<EOL><INDENT>redirect_to = settings.LOGIN_REDIRECT_URL<EOL><DEDENT>elif netloc and netloc != request.get_host():<EOL><INDENT>redirect_to = settings.LOGIN_REDIRECT_URL<EOL><DEDENT>auth_login(request, form.get_user())<EOL>return redirect(redirect_to)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>form = authentication_form(request)<EOL><DEDENT>current_site = get_current_site(request)<EOL>context = {<EOL>'<STR_LIT>': form,<EOL>redirect_field_name: redirect_to,<EOL>'<STR_LIT>': current_site,<EOL>'<STR_LIT>': current_site.name,<EOL>}<EOL>if extra_context is not None:<EOL><INDENT>context.update(extra_context)<EOL><DEDENT>request.current_app = current_app<EOL>return TemplateResponse(request, template_name, context)<EOL>
Displays the login form and handles the login action.