Skip to Content
Build Your First Flask App
Render HTML

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="">CODECADEMY</a> '''



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

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


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

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


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!

Folder Icon

Sign up to start coding

Already have an account?