#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 a logout page, I want you to just think about this for a second. We don't need a physical page, right?
0:11 We don't need that actual page to browse to rather, we just need something to force the user to log out.
0:18 So if you hit the URL of logout page, it will log you out. It doesn't actually need to render a page. It could redirect you back to another page.
0:28 So let's head into our routes.py file. Let's just pop down here pop it in here next to login page, makes a bit of sense and let's create app.route
0:42 for logout to page and login required. This is important because what we're saying is you can access this page until you're logged in
0:55 so there's no point clicking logout until you logged in. So, let's create a route a function, sorry, called logout page.
1:09 And all it's going to use is called call another beauty from Flask login called logout user, that's it. Return, redirect, as I alluded to before
1:25 we're just going to redirect the person to another page. Let's take them back to index and that's it we've just logged the user out.
1:34 So we're logged in. We will browse to logout page, /logout page. That will log us out, and let's demonstrate that now. Bring up our browser once again.
1:47 All right, let's go to the home page, right? Now, we can go to pybites_dashboard redirects us to the login page
1:57 throw in my username, Julian, logs us in. Now we'll go back to index you can see that we're still able to access the website
2:08 go back to dashboard, yep, we're still logged in. Now, let's go to logout page. And of course, I fell into that trap
2:23 of not actually importing logout user. So let's do that now. Pop up the top, we've got login user, we've got user_mixin.
2:35 The last thing we have is logout user. Start the app again. Let's log ourselves in.
2:57 Julian and abc 123 logged in and now watch what happens. Log out page and it redirects us to index. And if I try to go back to the pybites_dashboard
3:13 it redirects us to the login page. So that's how I can prove to you, I suppose that we were logged in.
3:21 Then once we clicked logout or typed it at the top it then logged us out, our session was null and void and when we went back to our dashboard
3:31 it then redirected us to log in again. And that, after this many videos, is Flask login. I know it's complex, I know it's crazy.
3:39 So just continue playing. Let's do a quick wrap-up and then you can move on.


Talk Python's Mastodon Michael Kennedy's Mastodon