To use the views in django-password-policies the same templates used by the views in django.contrib.auth can be used, except the templates to send the password reset email.
Note
Because django-password-policies is intended to be highly reusable it does not include any other templates than the ones used for testing the application. It is left to programmers using django-password-policies to create templates for projects as needed.
Used in the view PasswordChangeDoneView.
Displays a message that a password change has been completed successfully. Has no context variables.
Used in the view PasswordChangeFormView.
Displays the form to change a password. Has the following context variables:
The form used to change the user’s password.
If a password change is forced the view will remember the URL the user wanted to visit before being redirect to this view. By default, the path that the user should be redirected to upon successful password change is stored in a query string parameter called “next”.
Note that if you provide a value to redirect_field_name, you will most likely need to customize your login template as well, since the template context variable which stores the redirect path will use the value of redirect_field_name as its key rather than “next” (the default).
Used in the view PasswordResetCompleteView.
Displays a message that a password reset has been completed successfully. Has the following context variables:
The URL of the login page.
Used in the view PasswordResetConfirmView.
Displays the form to reset a password. Has the following context variables:
The form used to reset the user’s password.
Used in the view PasswordResetDoneView.
Displays a message that a password reset has been started and that an email with instructions has been sent to the user. Has no context variables.
Used in the form PasswordResetForm to send the password reset email.
This template is used to generate an HTML-attachment for the email. Has the following context variables:
The domain name.
The name of the site.
The HTTP protocol. Either http or https.
The user’s email address.
The signature token to use in a one-time secret URL.
The timestamp token to use in a one-time secret URL.
A base36-encoded string representig the user id.
The user instance.
The instance of the request.
Used in the form PasswordResetForm to send the password reset email.
This template is used to generate the message body of the email. Has the following context variables:
The domain name.
The name of the site.
The HTTP protocol. Either http or https.
The user’s email address.
The signature token to use in a one-time secret URL.
The timestamp token to use in a one-time secret URL.
A base36-encoded string representig the user id.
The user instance.
The instance of the request.
Used in the view PasswordResetFormView.
Displays the form to start a password reset. Has the following context variables:
The form used to identify the user by his/her email address.
Used in the form PasswordResetForm to send the password reset email.
This template is used to generate the subject of the email. Has the following context variables:
The domain name.
The name of the site.
The HTTP protocol. Either http or https.
The user’s email address.
The signature token to use in a one-time secret URL.
The timestamp token to use in a one-time secret URL.
A base36-encoded string representig the user id.
The user instance.
The instance of the request.
Note
Minimal example templates can be found inside the tests module of django-password-policies.
django-password-policies includes a Django URLconf which sets up URL patterns for the views in django-password-policies. This URLconf can be found at password_policies.urls, and so can simply be included in a project’s root URL configuration. For example, to place the URLs under the prefix /password/, one could add the following to a project’s root URLconf:
(r'^password/', include('password_policies.urls')),
Users would then be able to change their password by visiting the URL /password/change/ or to reset their password by visiting the URL /password/reset/.
To use django-password-policies in a Django project add password_policies to the INSTALLED_APPS setting of a project.
For example, one might have something like the following in a Django settings file:
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'django.contrib.messages',
'password_policies',
# ...other installed applications...
)
For now this app uses the PickleSerializer. This needs to be set up in the Django settings file:
SESSION_SERIALIZER='django.contrib.sessions.serializers.PickleSerializer'
To create the database tables needed by django-password-policies simply run the following inside a project’s root directory:
$ python manage.py syncdb