Serving HTML pages

First, to make our hello function respond with HTML, all we have to do is change it like this:

def hello():
    return "<html><head><title>Hi there!</title></head><body>Hello World!</body></html>", 200

In the preceding example, hello is returning a HTML formatted string and a number. The string will be parsed as HTML by default while 200 is an optional HTTP code indicating a successful response. 200 is returned by default.

If you refresh your browser with F5, you'll notice that nothing has changed. That's why the Flask development server is not reloading when the source changes. That only happens when you run your application in debug mode. So let's do that:

app = Flask(__name__)
app.debug=True

Now go to the terminal where your application ...

Get Building Web Applications with Flask now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.