Build a Python Web Server with Flask: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
| Line 42: | Line 42: | ||
[[File:Screenshot 2023-07-22 at 7.09.24 am.png | 900px]] | [[File:Screenshot 2023-07-22 at 7.09.24 am.png | 900px]] | ||
* Now open your web browser and enter the | * Now open your web browser and enter the IP address of your Raspberry Pi. | ||
* You can find the IP address of your Pi by hovering your mouse over the WiFi symbol. | |||
** Or by entering the URL '''localhost''' in the browser search bar. | |||
** Or entering the command '''ifconfig''' in a new Terminal window. | |||
* You should see this response. | * You should see this response. | ||
[[File:Screenshot 2023-07-22 at 8.00.43 am.png | 900px]] | |||
Revision as of 22:01, 21 July 2023
Build a Python Web Server using Flask
Install Flask
- Open the Terminal
- Enter the command pip3 install flask
- Make a new directory named webapp using the Terminal command mkdir webapp
- Enter the new directory with the command cd webapp
First web application =
- Open up Thonny.
- Paste the following code into Thonny.
- Save the file as app.py in the webapp directory.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def index():
return 'Hello world'
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
Run Flask from Terminal
- Open the Terminal
- To run the app.py program enter the command python3 app.py from within the /home/pi/webapp directory
- You should see a similar response.
- Now open your web browser and enter the IP address of your Raspberry Pi.
- You can find the IP address of your Pi by hovering your mouse over the WiFi symbol.
- Or by entering the URL localhost in the browser search bar.
- Or entering the command ifconfig in a new Terminal window.
- You should see this response.