Book Image

Building Web Applications with Flask

By : Italo M Campelo Maia, Jack Stouffer, Gareth Dwyer, Italo Maia
Book Image

Building Web Applications with Flask

By: Italo M Campelo Maia, Jack Stouffer, Gareth Dwyer, Italo Maia

Overview of this book

Table of Contents (17 chapters)
Building Web Applications with Flask
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 is running, type Ctrl + C then restart the server. You will notice a new output besides the URL where your server is running—something about "stat". That indicates your server will reload the...