cradmin_activate_account — An activate account workflow

The purpose of the django_cradmin.apps.cradmin_activate_account app is to provide a general purpose activate account workflow.

It is designed to work with any user model as long as it has an email field or property and an is_active-object like the Django User model or an activate_user()-method.


Add the following to INSTALLED_APPS:

    # ...

And add something like this to your root url config:

urlpatterns = patterns(
    # ...
    url(r'^activateaccount/', include('django_cradmin.apps.cradmin_activate_account.urls')),
    # ...

Quick start

If you install and setup the app as explained above, you just need to set the DJANGO_CRADMIN_SITENAME setting:


Now you should be able to use the ActivationEmail class to initiate account activation.

The ActivationEmail class

class ActivationEmail(request, user, next_url=None)

Bases: django_cradmin.apps.cradmin_email.emailutils.AbstractEmail

Handles account activation. Sends an email with a link that the user clicks to activate their account.


from django_cradmin.apps.cradmin_activate_account.utils import ActivationEmail

def myview(request):
    someuser = get_some_user()  # Insert your code to determine the user to activate here
    ActivationEmail(request=request, user=someuser).send()
  • request – A Django HttpRequest object.
  • user – The user you want to activate. Must have an email attribute or property.
  • next_url – An optional URL to redirect to after the user has activated their account.
appname = 'cradmin_activate_account'

The name of the app. Used for If you override this, you also have to override get_activate_url() and return the URL to a view that pops a GenericTokenWithMetadata with the changed appname.


Get the activate account view URL.


Get the context data of the email templates.


Get the email sender address.

Defaults to the DJANGO_CRADMIN_ACTIVATE_ACCOUNT_FROM_EMAIL setting falling back on the DEFAULT_FROM_EMAIL setting.


Get the value to use for the expiration_datetime attribute of GenericTokenWithMetadata.


Required settings:
The name of the site. You must set this setting unless you override the email subject and message templates as explained in Email templates and how to override them.
Optional settings:
Defaults to the DEFAULT_FROM_EMAIL setting.
The URL to redirect to when the account has been activated. Defaults to the LOGIN_URL setting.

How it works

Step One — Send the activate account email

First we generate a token using cradmin_generic_token_with_metadata — Secure generic tokens with metadata. This is a single use token with the user and the next url as metadata. We send an email with a link containing this token.

Step two — Activate the account

When the user clicks on the email, we get the user and next url from the token (which is part of the URL). If the token validates, we activate the account, add a success message using the Django message framework, and redirect to the next url.

Email templates and how to override them

You can override the following templates:

Override this to set the email subject.
Override this to change the email message.

All of the email templates get the following context variables:

  • DJANGO_CRADMIN_SITENAME: The value of the setting with the same name.
  • activate_url: The URL that users should click to activate their account.
  • user: The user that is activating their account.

UI message templates and how to override them

You do not have to override the entire templates to adjust the text in the UI. We provide the following templates for you to override:

The success message added to django.contrib.messages.success when the account is successfully activated. The activated user is available as the user template context variable.
The message shown in the UI when the activation link is invalid.
The message shown in the UI when the activation link is expired.