

Copy the “Hello Word” code below on your IDE and save it for example, as helloWorld.pyįrom flask import Flask app = Flask(_name_) def index(): return 'Hello world' if _name_ = '_main_': app.run(debug=True, port=80, host='0.0.0.0')ġ.Open your Python3 IDE, Thonny or Geany.Now, let’s create our first python WebServer with Flask: The final folder “tree”, will look like: /rpiWebServer /static /templates The Python WebServer Application Go to your newer created folder: cd rpiWebServerĪnd create the 2 new sub-folders: mkdir static On this folder, let’s create 2 other sub-folders: static for CSS and eventually JavaScript files and templates for HTML files (or more precisely, Jinja2 templates. There we will save our python files (application): /home/pi/Documents/Server The above command will create a folder named “Server”. The best when you start a new project is to create a folder where to have your files organized.
#THONNY TUTORIAL INSTALL#
Go to Terminal and enter: sudo apt-get install python3-flask The first thing to do is to install Flask on your Raspberry Pi. On this tutorial, we will use a Raspberry Pi as a local Web Server, where we will control via a simple webpage, 3 of its GPIOs programmed as outputs (acting as actuators) and monitor 2 of its GPIOs, programmed as inputs ( sensors). However, Flask supports extensions that can add application features as if they were implemented in Flask itself. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions. Introductionįlask is called a micro framework because it does not require particular tools or libraries. With Flask, will be very simple to control Raspberry GPIOs over the internet.Īfter you read this tutorial, please give a visit to its continuation: From Data to Graph: a Web Jorney With Flask and SQLite 1.

For this project here, we will use FLASK, a very simple and free microframework for Python.
#THONNY TUTORIAL HOW TO#
For example, on my tutorial: IoT - Controlling a Raspberry Pi Robot Over Internet With HTML and Shell Scripts Only, we have explored how to control a robot over the local network using the LIGHTTPD WebServer. Let’s create a simple WebServer to control things in your home.

Python WebServer With Flask and Raspberry Pi
