Building our first example

The Flask framework documentation explains building the first example. Modify the example from the documentation as follows:

#!/usr/bin/python3

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
return "Hello World!"

if __name__ == "__main__":
app.run('0.0.0.0')

Launch this example (available for download along with this chapter as flask_example.py) and it should launch a server on the Raspberry Pi Zero visible to the network. On another computer, launch a browser and enter the IP address of the Raspberry Pi Zero along with port number, 5000, as a suffix (as shown in the following snapshot). It should take you to the index page of the server that displays the message Hello World!:

The Flask framework-based web server on the Raspberry Pi Zero

You can find the IP address of your Raspberry Pi Zero using the ifconfig command on the command-line terminal.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.205.154