--Microweb framework for Python. --Flask is a web framework that is lightweight and doesn't have that many features. --It doesn't have as many features as Django. There are no extra features.
For MVC models such as Django, see below
Model: Describe business logic. Often involves database access View: In charge of screen drawing. Accepts input from users Controller: The role of the control tower that distributes URLs. Pass the data from the view to the model and vice versa
On the other hand, Flask takes the form of MVT instead of MVC. This is an acronym for Model, View, Template. MVC and MVT have almost the same content, but their roles are different.
Model: Same role as Model in MVC model View: Same role as Controller in MVC model Template: Same role as View in MVC model
cd FlaskApp
python3 -m venv venv
source venv\bin\activate
pip install Flask
pip freeze
If it looks like the following, it's OK for the time being
Click==7.0
Flask==1.1.1
itsdangerous==1.1.0
Jinja2==2.10.3
MarkupSafe==1.1.1
Werkzeug==0.16.0
Create the following source. Name the file views.py.
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World'
if __name__ == '__main__':
app.debug = True
#When launching the app under Linux environment, it is better to explicitly specify the IP and port number as shown below. The port number 5100 is appropriate.
app.run(debug=True, host='0.0.0.0', port=5100)
[Supplement to the 11th line of the source code] --host keyword argument: Specify the IP address of the server. --port keyword argument: Specify the port number. If not specified, the port number is 5000 by default. --debug keyword argument: Specifies whether to enable debug mode. If not specified, it is disabled by default.
Run the application with the following code
python views.py
OK if Hello World is displayed on the browser
Recommended Posts