Registration views¶
In order to allow users to register using whatever workflow is implemented by the registration backend in use, django-registration provides two views. Both are designed to allow easy configurability without writing or rewriting view code.
-
registration.views.
activate
(request, backend[, template_name[, success_url[, extra_context[, **kwargs]]]])¶ Activate a user’s account, for workflows which require a separate activation step.
The actual activation of the account will be delegated to the backend specified by the
backend
keyword argument; the backend’sactivate()
method will be called, passing theHttpRequest
and any keyword arguments captured from the URL, and will be assumed to return aUser
if activation was successful, or a value which evaluates toFalse
in boolean context if not.Upon successful activation, the backend’s
post_activation_redirect()
method will be called, passing theHttpRequest
and the activatedUser
to determine the URL to redirect the user to. To override this, pass the argumentsuccess_url
(see below).On unsuccessful activation, will render the template
registration/activate.html
to display an error message; to override thise, pass the argumenttemplate_name
(see below).Context
The context will be populated from the keyword arguments captured in the URL. This view uses
RequestContext
, so variables populated by context processors will also be present in the context.Parameters: - backend (string) – The dotted Python path to the backend class to use.
- extra_context (dict) – Optionally, variables to add to the template context. Any callable object in this dictionary will be called to produce the final result which appears in the context.
- template_name (string) – Optional. A custom template name to use. If
not specified, this will default to
registration/activate.html
. - **kwargs –
Any keyword arguments captured from the URL, such as an activation key, which will be passed to the backend’s
activate()
method.
-
registration.views.
register
(request, backend[, success_url[, form_class[, disallowed_url[, template_name[, extra_context]]]]])¶ Allow a new user to register an account.
The actual registration of the account will be delegated to the backend specified by the
backend
keyword argument. The backend is used as follows:- The backend’s
registration_allowed()
method will be called, passing theHttpRequest
, to determine whether registration of an account is to be allowed; if not, a redirect is issued to a page indicating that registration is not permitted. - The form to use for account registration will be obtained by
calling the backend’s
get_form_class()
method, passing theHttpRequest
. To override this, pass the keyword argumentform_class
. - If valid, the form’s
cleaned_data
will be passed (as keyword arguments, and along with theHttpRequest
) to the backend’sregister()
method, which should return aUser
object representing the new account. - Upon successful registration, the backend’s
post_registration_redirect()
method will be called, passing theHttpRequest
and the newUser
, to determine the URL to redirect to. To override this, pass the keyword argumentsuccess_url
.
Context
form
- The form instance being used to collect registration data.
This view uses
RequestContext
, so variables populated by context processors will also be present in the context.Parameters: - backend (string) – The dotted Python path to the backend class to use.
- disallowed_url (string) – The URL to redirect to if registration is
not permitted (e.g., if registration is closed). This should be
a string suitable for passing as the
to
argument to Django’s “redirect” shortcut. If not specified, this will default toregistration_disallowed
. - extra_context (dict) – Optionally, variables to add to the template context. Any callable object in this dictionary will be called to produce the final result which appears in the context.
- form_class (subclass of
django.forms.Form
) – The form class to use for registration; this should be some subclass ofdjango.forms.Form
. If not specified, the backend’sget_form_class()
method will be called to obtain the form class. - success_url (string) –
The URL to redirect to after successful registration. This should be a string suitable for passing as the
to
argument to Django’s “redirect” shortcut. If not specified, the backend’spost_registration_redirect()
method will be called to obtain the URL. - template_name (string) – Optional. A custom template name to use. If
not specified, this will default to
registration/registration_form.html
.
- The backend’s