#100DaysOfWeb in Python Transcripts
Chapter: Days 57-60: Flask Login
Lecture: Create a quick logout page

Login or purchase this course to watch this video and the rest of the course contents.
0:00 All right, to quickly create ourselves
0:02 a logout page, I want you to just think about this
0:05 for a second.
0:06 We don't need a physical page, right?
0:10 We don't need that actual page to browse to
0:13 rather, we just need something to force the user to log out.
0:17 So if you hit the URL of logout page, it will log you out.
0:22 It doesn't actually need to render a page.
0:24 It could redirect you back to another page.
0:27 So let's head into our routes.py file.
0:31 Let's just pop down here
0:34 pop it in here next to login page, makes a bit of sense
0:38 and let's create app.route
0:41 for logout to page
0:47 and login required.
0:49 This is important because what we're saying is
0:51 you can access this page until you're logged in
0:54 so there's no point clicking logout until you logged in.
0:59 So, let's create a route
1:02 a function, sorry, called logout page.
1:08 And all it's going to use is called call another beauty
1:11 from Flask login called logout user, that's it.
1:18 Return, redirect, as I alluded to before
1:24 we're just going to redirect the person to another page.
1:27 Let's take them back to index and that's it
1:31 we've just logged the user out.
1:33 So we're logged in.
1:35 We will browse to logout page, /logout page.
1:38 That will log us out, and let's demonstrate that now.
1:44 Bring up our browser once again.
1:46 All right, let's go to the home page, right?
1:51 Now, we can go to pybites_dashboard
1:54 redirects us to the login page
1:56 throw in my username, Julian, logs us in.
2:01 Now we'll go back to index
2:04 you can see that we're still able to access the website
2:07 go back to dashboard, yep, we're still logged in.
2:10 Now, let's go to logout page.
2:19 And of course, I fell into that trap
2:22 of not actually importing logout user.
2:25 So let's do that now.
2:30 Pop up the top, we've got login user, we've got user_mixin.
2:34 The last thing we have is logout user.
2:44 Start the app again.
2:50 Let's log ourselves in.
2:56 Julian and abc 123 logged in and now watch what happens.
3:03 Log out page and it redirects us to index.
3:09 And if I try to go back to the pybites_dashboard
3:12 it redirects us to the login page.
3:14 So that's how I can prove to you, I suppose
3:17 that we were logged in.
3:20 Then once we clicked logout or typed it at the top
3:23 it then logged us out, our session was null and void
3:27 and when we went back to our dashboard
3:30 it then redirected us to log in again.
3:32 And that, after this many videos, is Flask login.
3:36 I know it's complex, I know it's crazy.
3:38 So just continue playing.
3:40 Let's do a quick wrap-up and then you can move on.