Sign Me Up - Choosing & Using a Registration Package for... by Eleanor Stribling

This video features Eleanor Stribling at DjangoCon US 2016 in Philadelphia, Pennsylvania, USA.

Sign Me Up - Choosing & Using a Registration Package for... by Eleanor Stribling
0:18:04
Published August 22, 2016
439 views

Sign Me Up - Choosing & Using a Registration Package for Your Django Project by Eleanor Stribling

Registration steps to use a web app, as well as login and password reset functionality is a common requirement, but where do you begin implementing this in Django? Walking through an actual case study with code examples, novice programmers will learn some tips and tricks for finding and implementing the right framework.

Summary

Eleanor Stribling explains how to choose and use a Django registration package, using Django Registration Redux 1.4 with Python 3 and Django 1.9. She recommends checking a package’s requirements, compatibility, maintenance, usage, and documentation, then demonstrates how registration fits into a small Django project: defining a form from Django’s built-in user model, adding the package and sites app, installing registration templates, and including one URL pattern. She also shows how the order of `INSTALLED_APPS` affects template overrides and how to test registration emails locally with Django’s console email backend; the flow creates an inactive user, which is activated through the emailed link.

Key takeaways

  • Evaluate registration packages against current and future requirements, Django and Python compatibility, maintenance activity, adoption, and documentation.
  • Django Registration Redux builds on Django’s existing user model; a custom form selects the fields users submit, while the account remains inactive until email confirmation.
  • The basic setup involves installing the package, adding the sites and registration apps, creating registration templates, and including the package’s URLs in the project-level `urls.py`.
  • Put the registration app before `django.contrib.admin` or other apps that may contain competing templates when you want custom registration templates to be used.
  • Set Django’s email backend to the console backend during development so confirmation emails can be inspected locally before configuring an SMTP service for production.
  • Django Allauth was not chosen because social login was unnecessary for this simple project and would add complexity.

Summarised automatically from the transcript.

Transcript

3,573 words · auto-generated Show

Automatically transcribed, so expect mistakes in names and technical terms.

0:00

Speaker 1: Come on, no.

0:14

Speaker 2: So uh thanks for coming. The talk is called Sign Me Up. It's about choosing and using a registration package on your Django project. So before we start, I as she mentioned, I come from product sales like kind of set the stage. This is a novice level talk. It's supposed to be pretty simple and straightforward. If you've built an app from a tutorial once, you should be fine in it. This talk, you'll be totally okay. Even if you know some Python, you'll be totally okay. But I think this might also be useful for people who are teaching or who are mentoring younger developers who haven't done this before before. So hopefully this will at least give you some ideas about how to talk to them about Django and how especially how the file structure works. This talk will use Python 3, Django 1. 9, and the package I chose, Django Registration Redux

1:00

Speaker 2: 1. 4. So I just wanted to be up front with that because not all of these things work with all versions of other things. Just to be clear. And I'm going to cover the implementation of the registration flow. So basically how the package takes the user model, builds on that, and enables you to set something up with just a few templates and a few alterations so that you can do user authentication. So they've put in username and password, the user is created, but they they get an email, which they click on a link, then they are authorized and their account is active. So that's what I'm covering today. I'm not going to cover any of the email setup or site deployment. So actually sending the email, different topic, not going to go over it So just to be upfront with that, but I will show you how to test the emails on your on your local machine. So the origin

1:46

Speaker 2: story of this talk was I am not a full-time developer, but I work in a 10-person company, so I kind of do whatever. But this all started with a personal project. This Django app called Belize. And basically it's an app, it's in my GitHub repo. You can look at it if you want to. It definitely illustrates some things not to do when implementing Django registration readups. Uh still it needs a little refactoring, but so cautionary tale. It does work though, and it is on the web at Felize. com if you want to see what the end result was So I wanted to add this as a Django novice. And the reason I wanted to give this talk was that I found it really difficult to do. And after doing it, I was like, why was that so difficult? It is actually pretty straightforward. So that's why I wanted to do the talk. Three things I wanted to cover.

2:31

Speaker 2: Criteria and resources for choosing a registration package. There are actually quite a few. So things to think about as you're doing it. Again, as a product person, this is always very important to me. How the pieces of the package fit into the Django framework. This for me was the hardest part as somebody who had not used Django before. When you start with this, um Whether or not you remember this, but when it certainly when I started with it, it just seemed like a bunch of files and a bunch of folders doing a bunch of things. And I was just like, okay, I'll just type this here and I'll type this there. And it would somehow work. So I wanted to show sort of the tutorial I wanted of walking through like what you're changing and what it's doing. So uh that's the other objective. And then a couple of kind of gotchas that I ran into trouble with and took me an inordinate amount of time to figure out

3:19

Speaker 2: They're in the documentation, but they're kind of hidden, and I feel like they're things that other people who were trying to help me couldn't figure out right away. So I thought they might be common problems that people have, even though it's somewhere on the internet someone has explained it I should also mention my son's kind of a theme through this whole thing. For some levity, I would have put puppies, but I didn't have the rights to images of puppies, so it's my kid. So choosing a registration package. So setting the criteria, again, matching product requirements, you probably knew I was going to say that. I think a good from looking from the sort of the business side, but also working on my own project I would say definitely look at your immediate requirements, but maybe one level above. This particular package doesn't support certain things that I think eventually I will want to add.

4:05

Speaker 2: So a little bit of regret there on my part. Do as I say not as I do. Um but that's that's a really important criterion and to know what those requirements are because you could get really you know down a rabbit hole on this stuff. Um compatibility, so um Django registration redux, for example, does not not work with Django after 1. 8. So that might be trivial for you to upgrade, but in my experience upgrading is not necessarily trivial. So just keep that in mind. Maintenance and usage. So this to me is a really big one, especially when you're you're starting or you you know you don't want to use the bleeding edge. You just want something that works. and you can get done. One thing I was really looking for is something that is maintained well. So I checked commits on GitHub, I checked how many people were using it, how many people had forked it as a proxy.

4:51

Speaker 2: So I just wanted to get a feel for like how how frequently it was used. I could also find a bunch of tutorials online, which brings me to my fourth point, which is the quality of documentation. I feel like documentation is very much overlooked when working in software. It causes so many problems when there are not good examples out there. So I also picked a package where there was a lot of documentation, there were good YouTube videos. And I think it also helps when you're your teaching Teaching somebody who's new to this to be able to show them lots of different ways of explaining something. So if those are present, I think that's that's a good sign I wanted to introduce DjangoPackages. com if you don't already know about it. The site is, I love the site so much. It's got like a listing of basically every package you could want, and it lays out some characteristics that you can each package.

5:36

Speaker 2: So things like does it support OAuth? Does it work with Django 1. 5 or later? With Python 3, etc. So I think it's a really great resource and you can pruse it at your leisure. It also has links to the repos, which again I think are really useful for getting a feel of how frequently the code is maintained and how many people are using it. So this is kind of the big one for me was fitting this into the framework because honestly I had no clue what I was doing at first um and I didn't like I said didn't find anything very clear so um pivot pictures my son I decided to make because my other app was like such an intense expression of how confused I was when I first did this. I decided to make a really simple little kind of baby app for this. So it's called Fairy Tale Reviews because my son

6:25

Speaker 2: Super simple data model. You just leave a review of a fairy tale, you can sign in or sign up. So that's the registration piece. There we go. My name was slow apparently when I record this video. video. I don't live code and you know even my videos sometimes are are weird. So you can sign in with that, you can log in with the login form. So that's basically what Django Registration Redux does, that and registering the user. So once you log in, you can see a form. I talk faster than my video. You can see a form where you can actually write a review up at the top. So you click on write a review Or you can sign out, yes. And you click write review and there's the form. So that's basically what it is. And then you do the review and it shows up on the next page. So it's a very, very simple little app.

7:10

Speaker 2: Any sort of I think beginner Django user could could figure out what's going on in this. And it does work with the SQLite database. So there's none of the Postgres hassle. And there we go, my review of 12 Dancing Princesses, which is a great fairy tale. Check it out. you have not if you have not already. So this is the the file structure part. So I've left out some of the dunder events and the migration files and whatever. But you know high level this is these are the files that you've got. You've got the managed You've got your database. You've got your project in this case in the repo. It's called DjangoCon. That's why it's in brackets, parentheses rather, it's DjangoCon. And it gives you these files. And then there's the app folder which you create. And these are the default files. So I wanted to talk a little bit about what you need to add, because this really screwed me up as someone who's first learning Django.

8:00

Speaker 2: You have to obviously add a forms file, and in this app you would have done that anyway for the review writing. But you need to add it in order to create your user. And you have a templates folder where you have hopefully a base HTML file that you're going to extend with your templates. You have your folder of templates for your app. So those are the all of the ones that I'm going to show you. Oh sorry, all the the two that I showed you already, the form and then the page with all of the reviews on it. And then finally a folder called registration. So that's going to hold all your registration templates. This is one thing I wish I had at the beginning because I didn't know that you only had to alter a couple of these files and folders. Those are the ones. So

8:45

Speaker 2: the first step, five steps to doing this, pip install, Django registration redux, easy, right? Also update requirements, unreal. stickler for that. And then you create a form in user with the user model in forms. py. So you need to determine which fields you need. This goes back to requirements. Username and password are required and that's pretty clear in the documentation. which is pretty good around this. Other fields are built in, it's like first name and last name. So you could add those if you wanted to. You don't have to. And of course you can also extend the user model, but I'm not going to cover that here. So this is basically all you have to do. It's just a few lines. You want to import the user model and then you create this user form. And the fields are the three that I want in my form So that's all you have to do there.

9:30

Speaker 2: Pretty straightforward. You have to install the registration app in settings. py. So here it is, this is how the first tutorial I found told me to do it. And I highlighted here because it later caused me problems. So anyway, you add that, you have to make sure Django. contrib. sites is there, and then you should be good. The other thing I wanted to mention, I'm not going to talk about it a lot, but there are a bunch of variables you can set to control the user experience. using Django registration readups. These are actually pretty well explained in the docs and I I put some of the ones I use here. So if you want to check out the repo, they're all there. Next, getting the registration template. So when you think about it, there's a ton of different views you'll see when you go through registration.

10:16

Speaker 2: or resetting your password or being authorized or whatever. I started writing all these myself and I discovered a nice person has done it for us. So you can clone this repo. These are all the foreign, there's a lot of different HTML files in here. So you can just clone this and then customize them yourself and it's so much easier than trying to write them all yourself and you can spend time having fun with CSS. and such. And then you add to your URLs. py, not the one in your app. So this really confused me. I thought it had to be in the app. It is not in fact in the app. If you look at the other thing I made in my repo, it's really embarrassing. I've got like lines and lines and lines of of trying to import every single one of these views, like out every single pattern rather.

11:01

Speaker 2: You don't have to do that. You just have this one Online in URLs. py. And that's it. That's all you have to do. I spent a lot of time doing that, and I didn't have to. But there are two problems that really Two issues that really caused me trouble, took a ton of time to figure out, and I wanted to mention those just in case it saves you time. So the first problem I had, and this was honestly the most irritating thing ever, was I couldn't get the custom templates to work. So I downloaded the repo. I spent all this time on the CSS and and all this stuff in the HTML. I put in Bootstrap, I did all kinds of amazing things, and then I I actually tried to use it and it didn't work. So there I had the example of typing this as a template to see if it was

11:47

Speaker 2: my custom template and then when I actually went to it on my local host I got this for the password reset which was painful and sad. It looks nice but it's not what I wanted. So how to fix this? Well The import order in installed apps and settings. py was my problem. I did not realize this for quite some time. It was again extremely upsetting. But anyway, the problem was I didn't put the registration app before contrib. admin. That was the problem because contrib. admin it it will go through that first if it's first in the list So that was very unfortunate and took forever, but now you know. So you don't have to worry about that. Also the way I organize this, I should mention if you were doing a bigger um project, you might not want to put all

12:34

Speaker 2: the registration templates in one app, but in this case I did, so I had to import my app before the registration. So then it works. So that was, you know, a couple days of my life. The next problem I had was testing emails in dev. So I wanted to set it up, you know, like I wanted to to put it out, put it out there on the internet. I wanted to use Heroku to deploy it. I knew I could use the SendGrid plugin, I think they call it. All of all that was fine. But the problem was I wanted to test this in Dev and make sure it kind of at least sort of worked first before I went through all that trouble. So to do that, what what I started with was Get the video going here. So I started, I used my form and filled in all of these these fields.

13:19

Speaker 2: The thing about submitting this form, I'll say as this is going, is it does actually create a user Even if you get the error I'm about to get, it just doesn't make them active and it doesn't send an email. Because it's not set up to send an email. You're telling Jaygo send an email and it can't. So you get this error, the connection refused error I've seen this so many times. It brings back memories. The way to solve this is actually very simple, but it does involve adding another line of code in another file, which again is what I think is really hard about Django when you don't know it because it's it's just like so many different things you need to add in all these different places. In retrospect it's pretty straightforward but But that's how it is when you're learning. So you need to go in your settings. py and you need to add

14:06

Speaker 2: one line of code with a variable called email backend. And this is important both for actually sending emails and printing to the console. You'll see it says console in there, which is important for the the printing to the console part. If you do actually implement like an email server, if you do like to put Chiroku, you use ThinkGrid and all that stuff, you do have to change the cons console to SMTP, which I learned only after harassing SendGrid for a full day about why their stuff didn't work. So then that works. You get that template and then it will print it all out in your console. The way I did it, I set the site ID to localhost and in the repo there are instructions for that. I didn't want to cover that here, but I just set it to localhost colon 8000 or the port of your choice, I guess. And um

14:51

Speaker 2: and then it works. So this will just demonstrate it. This is again why I don't live code because the videos are even hard for me. All right, and then yeah, and now the account is activated. So that's a great way to test it before you you push it out. And if you have problems at that point, obviously you can see them before you go to production So a bunch of resources for this talk. Definitely if you want to check out my the repos on GitHub, this last one I did, the fairy tale one, is very simple. It's not complex at all. I think it's pretty straightforward for explaining it. And the code is commented. If you want to show someone what not to do, or if you want to compare your your app to somebody else who didn't know what they were doing and see if there are any similarities. I highly recommend checking out the other repo I have.

15:38

Speaker 2: It does work, but it does have a lot of extra code So it does show where the confusion points were with say importing a bunch of URL adding a bunch of URL patterns that I really didn't need and stuff like that. I used Django 1. 9 and Django Registration Redux 1. 4 once again. You do need to use Django 1. 8 or higher with 1. 4, so that's something to keep in mind if this is something you want to use. or teach. So that's about it. This is me. Thank you so much for listening. And if you have any questions, happy to take them.

16:17

Speaker 3: Thank you so much, Eleanor. Looks like we've got a question up here. Uh

16:26

Speaker 4: hey, uh thank you for the talk. Um I was actually struggling with user registration like just last week and I had to deal with registration redux and then um I was curious if you also looked into Django All Auth, because like I found that one slightly less confusing, but I don't know like if there was any real difference other than that one also like um supports Like social sites, like logins.

16:51

Speaker 2: Yeah, that that's actually why I didn't use it because I thought that would add a layer of complexity and I didn't really need that. So I I said, ah forget it. I'll just go with registration redux. Maybe I should have gone follow-off. All lost, like all yeah. Django packages. com. Uh

17:14

Speaker 5: for somebody who's super new to Django, the is the registration Redux actually making a user itself or is it using I'm assuming it's using the Django's user. Okay Just making sure.

17:25

Speaker 2: Yeah, that's what you're doing in that form step is you're you're you're importing the user and then you're making the form with those fields that you want. So yeah, it's it's totally leveraging that. And like I said, when you first, when they first sign up, it creates it, it creates that user in the database. Okay. And it just doesn't activate it. So that that whole like link clicking is activating the user. Thank you.

Questions this talk answers

How do I choose a Django registration package?

Start with your current and likely near-term requirements, then check compatibility with your Django and Python versions, maintenance and usage, and the quality of the documentation. DjangoPackages.com is useful for comparing packages and finding their repositories.

Discussed at 3:19

How do I add Django Registration Redux to a Django project?

Install the package, add it to the project’s requirements and `INSTALLED_APPS`, create a user form based on Django’s user model, add the registration templates, and include the package’s registration URLs in the project-level `urls.py`.

Discussed at 8:45

Why aren't my custom Django registration templates being used?

Check the order of `INSTALLED_APPS` in `settings.py`: the registration app must come before `django.contrib.admin`, so Django finds your custom templates first. If the templates are in your own app, that app also needs to precede the registration app.

Discussed at 11:47

How can I test Django registration emails locally?

Set Django’s `EMAIL_BACKEND` to the console backend in `settings.py`, configure the local site ID, and Django will print the activation email in the console instead of trying to send it. For real delivery, switch the backend from the console backend to SMTP.

Discussed at 13:19

Why choose Django Registration Redux instead of Django Allauth?

The speaker chose Registration Redux because social-login support in Allauth would add complexity that the project did not need. The decision was based on keeping a simple registration flow.

Discussed at 16:51

Does Django Registration Redux create its own user model?

No. It uses Django’s built-in user model: the form imports that model and selects the fields to expose. Submitting the form creates the user in the database but leaves the account inactive until the activation link is clicked.

Discussed at 17:25

Note: We understand that names change, people change, and bodies change. We respect each individual's journey and privacy. If you have any concerns about a video or need us to remove content, please don't hesitate to contact us. We will handle your request with care and promptly address any issues.

More videos by Eleanor Stribling

More videos from DjangoCon US