In the previous exercise, we were able to write the login code. Now in this section, we will show the information related to the logged-in user.

Let’s 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="[email protected]", username="TheCodeLearner",password="!aehashf0qr324*&#W)*E!") login_user(user) return render_template("logged_in.html", current_user=user ) return 'Bad login'

Now when a user logs in successfully they are sent to a page showing our logged-in info. Most likely in our application, we will be serving dynamic pages of HTML. We can use Jinja templates to render the data from the backend. To display the user, 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 our users to see their data when they log in!



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

In logged_in.html, add a <p> element with a Jinja template to display the logged-in user’s username.


Nice work, now log in with the provided credentials to view the displayed username.

Sign up to start coding

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?