Skip to Content
Introduction to Authentication with Flask
Show Logged in user

In the previous lesson we were able to write the login code. Now in this section we will show the logged in user.

Lets zoom into this code: Notice how we pass in user into the current_user object. We will be using that current_user object in our html.

user = User(email="", username="TheCodeLearner",password="!aehashf0qr324*&#W)*E!") login_user(user) return render_template("logged_in.html", current_user=user ) return 'Bad login'

Now when we login successfully we are sent to a page showing our logged in info. Most likely in our application you will be serving dynamic pages of html. We can use Jinja templates to render our data from the backend. To display the user we pass it in from the endpoint and access that variable in our html.

<h1>Welcome to Our Home Page</h1> <p>Welcome back {{current_user.username}}</p> <a class="blue pull-left" href="{{ url_for('index') }}">back</a>

This will enable us to see our data when we log in!



Use the login_manager decorator in our code so that we have a valid endpoint.


Use the object that allows us to see which use is currently logged in.

Folder Icon

Sign up to start coding

Already have an account?