|
views.login(request[, template_name, redirect_field_name, authentication_form])
URL name: login
See the URL documentation for details on using named URL patterns.
Here's what django.contrib.auth.views.login does:
If called via GET, it displays a login form that POSTs to the same URL. More on this in a bit.
If called via POST, it tries to log the user in. If login is successful, the view redirects to the URL specified in next. If nextisn't provided, it redirects to settings.LOGIN_REDIRECT_URL (which defaults to /accounts/profile/). If login isn't successful, it redisplays the login form.
It's your responsibility to provide the login form in a template called registration/login.html by default. This template gets passed four template context variables:
form: A Form object representing the login form. See the forms documentation for more on Form objects.
next: The URL to redirect to after successful login. This may contain a query string, too.
site: The current Site, according to the SITE_ID setting. If you don't have the site framework installed, this will be set to an instance of RequestSite, which derives the site name and domain from the current HttpRequest.
site_name: An alias for site.name. If you don't have the site framework installed, this will be set to the value ofrequest.META['SERVER_NAME']. For more on sites, see The "sites" framework.
If you'd prefer not to call the template registration/login.html, you can pass the template_name parameter via the extra arguments to the view in your URLconf. For example, this URLconf line would use myapp/login.html instead:- (r'^accounts/login/, 'django.contrib.auth.views.login', {'template_name': 'myapp/login.html'}),
复制代码 |
|