Learn

The response we return from a view function is not limited to plain text or data. It can also return HTML to be rendered on a webpage:

@app.route('/') def home(): return '<h1>Hello, World!</h1>'

We can use triple quotes to contain multi-line code:

@app.route('/') @app.route('/home') def home(): return ''' <h1>Hello, World!</h1> <p>My first paragraph.</p> <a href="https://www.codecademy.com">CODECADEMY</a> '''

Instructions

1.

Update your home() function to return Hello, World! as a <h1> heading.

Run app.py and view your page at http://localhost:5000/ in the browser.

2.

Now, update reporter() to return Reporter Bio as a <h2> heading.

Navigate to http://localhost:5000/reporter in the browser.

3.

Let’s add another tag to the HTML in reporter()! After the <h2> heading, add an <a> tag with the text Return to home page that links back to http://localhost:5000/. To have the code run properly in the learning environment, use just the relative path "/" as the href attribute.

Run the app and try clicking on the link you created!

Sign up to start coding

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?