Django: Getting Started Transcripts
Chapter: Users and Account Management
Lecture: People app: an app with users

Login or purchase this course to watch this video and the rest of the course contents.
0:00 I'm going to start here by creating a new app that does some things with users.
0:05 Just open the terminal and I'm going to run the start app management command. I'm going to do that for an app called people.
0:19 The people listing now shows up in pycharm. But before I can add some code I need to update settings. The people apps now ready to go.
0:32 Nothing I haven't seen before. Let me just replace the stub code.
0:49 What I'm going to do next is create a new view that lists all the users in the site. This might be something like a find your friends function.
0:58 Before writing the view, I need some imports you haven't seen before. The first one is the login required decorator that I mentioned a minute ago.
1:06 The 2nd one is the user object, then the usual rendering shortcut and a new one Get object or 404. I'll come back to that one in a bit.
1:17 Now for the view this view is nice and small. The data context contains one thing, a query set filled with all the users in the database.
1:35 The user object is a model like any other. So finding the non staffed users is just a call to filter with the right arguments.
1:43 With the queried users in the context, the render shortcut gets called like other views I've written.
1:48 The only real new thing here is the login required decorator, by placing that over the view function.
1:56 I'm indicating to Django that you must be logged in to see this page. If you are not logged in, Django will automatically redirect you to a login page.
2:05 It even sets a hidden field on the login page, so a successful login will send you back to this page quite handy.
2:13 The profile listing page will contain links to each user's profile page. Well, I've got this file open. Let me add a view for that as well.


Talk Python's Mastodon Michael Kennedy's Mastodon