There are several approaches to user registration, we can do it on a single step, or we can do it on
2 steps with a confirmation email being sent to the given address. There are several ways you can structure
your registration flow, either two simple questions (
) or multiple questions through
several pages, you name it, we always write user registration flows.
Is you ask me, I've always preferred to write a simple one, ask for an
and ask for the
rest of the information I need on a separate
page, things like name, date of birth, country, city,
mobile number or other stuff I might need. But you want as least friction as possible on the registration process,
specially if you're trying to get your first users, that's why I don't even send confirmation emails when I just launched
something. I start asking for confirmation when I already got some users and I have people constantly signing up, otherwise,
it's not worth the effort or the network traffic, plus the complexity of sending it asynchronously with a message queue.
That's why I thought of writing a reusable django app to solve this, I was working on it for a while, taking the good parts
of all the registration flows I've written, until I found
and just switched to that library.
This is way better that anything I could have written myself, it's being used by many people, has an active maintainer, works out of the box and supports single and two steps registration flows so, why reinventing the wheel if it's already there?, I'm using it for a couple of personal projects I'll be in the upcoming months (or not... you know...) and it's incredible how easy it makes it to implement user registration, allowing me to start working on actual features and functionality in almost no time.
Let's get started
To install it, you just need to
it as any usual
pip install django-registration
For the simple one step registration flow or the HMAC Based workflow, you don't need to do anything else.
django-registration , supports three different workflows:
INSTALLED_APPSas you will need to install one model to perform the verification step. If you need a two steps account creation because you require email verification, the recommended way is to use the HMAC flow.
The basic one step registration flow is the easiest way to register new users, if you're just deploying something for fun and it's intended mostly for your personal use but want to allow other people to use it, I don't think you need to verify email and go through all that hassle unless you get serious about it, so in my case, the intended user for my project is just myself, but if someone else wants to use it, I'm OK with that, I assume if you want to use something you'll just provide a legit email because it's on your own interest.
I decided to go for a
flow, as I don't really care if anyone provides an nonexistent email, I'm the one who will mostly
be using this, so, I guess it's OK,
allows me to restrict new accounts from being created just by adding
REGISTRATION_OPEN = False
Each registration flow comes with its own set of views and urls and you'll have to create your custom template and form if you needed, you'll most probably end up customizing some behavior, but it's really easy to do, most of the core, boring and repetitive work of creating the registration workflow is done for you and works out of the box.
In this case, for the one step all I had to do was the following:
in my urls configuration
from django.conf.urls import url from django.conf.urls import include urlpatterns = [ # Some url patterns url(r'accounts/', include('registration.backends.simple.urls')), # More url patterns ]
REGISTRATION_OPEN = True
, this is the default value, but
better explicit than implicit
3.- By default, after successful registration the user will be redirected to
, but you can customize this behavior by
and overriding the method
, in my case,
4.- By default,
, this can be overridden by supplying your
argument when adding the default
or by subclassing it and setting the
attribute or implementing
. In my case, I opted for passing an argument to the
method when addind the
from registration.backends.simple.views import RegistrationView from django.conf.urls import url from django.conf.urls import include from .forms import UserRegistrationForm urlpatterns = [ # Some url patterns url(r'accounts/register/$', RegistrationView.as_view( form_class=UserRegistrationForm ), url(r'accounts/', include('registration.backends.simple.urls')), # More url patterns ]
5.- Customize the registration template, this flow only needs one template called
and it will
pick it up automatically, the
will add the
variable to the
and it will contain a
all for free.