Skip to content

Commit eb9b7ab

Browse files
gitaarikmxsasha
authored andcommitted
Fixed #21661 -- Expanded authentication views documentation
1 parent e272904 commit eb9b7ab

File tree

1 file changed

+69
-9
lines changed

1 file changed

+69
-9
lines changed

docs/topics/auth/default.txt

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -673,18 +673,78 @@ Django provides several views that you can use for handling login, logout, and
673673
password management. These make use of the :ref:`stock auth forms
674674
<built-in-auth-forms>` but you can pass in your own forms as well.
675675

676-
Django provides no default template for the authentication views - however the
677-
template context is documented for each view below.
676+
Django provides no default template for the authentication views. You should
677+
create your own templates for the views you want to use. The template context
678+
is documented in each view, see :ref:`all-authentication-views`.
678679

679-
The built-in views all return
680-
a :class:`~django.template.response.TemplateResponse` instance, which allows
681-
you to easily customize the response data before rendering. For more details,
682-
see the :doc:`TemplateResponse documentation </ref/template-response>`.
680+
.. _using-the-views:
683681

684-
Most built-in authentication views provide a URL name for easier reference. See
685-
:doc:`the URL documentation </topics/http/urls>` for details on using named URL
686-
patterns.
682+
Using the views
683+
~~~~~~~~~~~~~~~
687684

685+
There are different methods to implement these views in your project. The
686+
easiest way is to include the provided URLconf in ``django.contrib.auth.urls``
687+
in your own URLconf, for example::
688+
689+
urlpatterns = [
690+
url('^', include('django.contrib.auth.urls'))
691+
]
692+
693+
This will include the following URL patterns::
694+
695+
^login/$ [name='login']
696+
^logout/$ [name='logout']
697+
^password_change/$ [name='password_change']
698+
^password_change/done/$ [name='password_change_done']
699+
^password_reset/$ [name='password_reset']
700+
^password_reset/done/$ [name='password_reset_done']
701+
^reset/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$ [name='password_reset_confirm']
702+
^reset/done/$ [name='password_reset_complete']
703+
704+
The views provide a URL name for easier reference. See :doc:`the URL
705+
documentation </topics/http/urls>` for details on using named URL patterns.
706+
707+
If you want more control over your URLs, you can reference a specific view in
708+
your URLconf::
709+
710+
urlpatterns = [
711+
url('^change-password/', 'django.contrib.auth.views.password_change')
712+
]
713+
714+
The views have optional arguments you can use to alter the behavior of the
715+
view. For example, if you want to change the template name a view uses, you can
716+
provide the ``template_name`` argument. A way to do this is to provide keyword
717+
arguments in the URLconf, these will be passed on to the view. For example::
718+
719+
urlpatterns = [
720+
url(
721+
'^change-password/',
722+
'django.contrib.auth.views.password_change',
723+
{'template_name': 'change-password.html'}
724+
)
725+
]
726+
727+
All views return a :class:`~django.template.response.TemplateResponse`
728+
instance, which allows you to easily customize the response data before
729+
rendering. A way to do this is to wrap a view in your own view::
730+
731+
from django.contrib.auth import views
732+
733+
def change_password(request):
734+
template_response = views.password_change(request)
735+
# Do something with `template_response`
736+
return template_response
737+
738+
For more details, see the :doc:`TemplateResponse documentation
739+
</ref/template-response>`.
740+
741+
.. _all-authentication-views:
742+
743+
All authentication views
744+
~~~~~~~~~~~~~~~~~~~~~~~~
745+
746+
This is a list with all the views ``django.contrib.auth`` provides. For
747+
implementation details see :ref:`using-the-views`.
688748

689749
.. function:: login(request, [template_name, redirect_field_name, authentication_form, current_app, extra_context])
690750

0 commit comments

Comments
 (0)