Here are resources for Django user management:
In order to demonstrate DRF permissions, I’m going to have to set up a whole bunch of Django
auth pieces. I’m going to spend this lesson prepping, and the next lesson diving into the actual DRF permissions.
django.contrib.auth module is new to you, then you might want to stick around. Everything that I show you inside of this lesson is moving towards the fact that I need a couple more accounts than just the
I’m going to create an account called
indy that has the staff setting set to
True, and another account called
marion that’s just general usage. Out of the box, Django no longer comes with a login page. In order to be able to play with this and have accounts log in and log out, I’m going to need to create a login page to go with these accounts.
01:56 This specifies what password validators Django runs when you create an account. Because I’m just going to be messing around and I don’t want to have to deal with this. I’m going to zero all of this out.
The second thing I need to do is create a login page. That’s going to be rendered as a Django template. In order to do that, I’m going to need a
templates/ directory, so I’m going to make that inside of the
BASE_DIR is defined near the top of the
settings file and specifies where the project exists, so
templates/ is relative to that
BASE_DIR. If you happen to be using an older version of Django, do note that Django 3 uses the
This HTML code goes inside of a file called
login.html inside of that newly created
templates/registration/ directory. The
contrib.auth module automatically looks for a template with this name, and that’s how these pieces are wired together. With all that set up, I’m now ready to use the Django admin to create a couple of accounts. In a window offscreen, I’m running the Django development server, and now I’m going to point the browser at
The first account I’m going to create is for
indy. I type in the username and passwords, being grateful that I turned off the validators. And when I hit SAVE, the admin will let me edit this newly created account.
Become a Member to join the conversation.