When you try to start flask, create a local host first and display "hello, flask!" There. However, many people may not understand the contents of the code at that time. So, I wrote down the meaning of each one.
Windows PC Visual Studio Code ver.1.45.1 Python 3.8
pip3 install flask
to install without permission.python : app.py
app.py
# coding: utf-8
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello, Flask!"
if __name__ == "__main__":
app.run()
A screen like this appears. (I wonder if it was a hindrance to the margins ...)
app.py
# coding: utf-8
from flask import Flask
app = Flask(__name__)
@app.route("/test")
def hello():
return "Hello, Flask!"
if __name__ == "__main__":
app.run(debug=True)
from flask import Flask
For, load a module called flask. If you talk about the contents of flask, the story seems to be out of sync, so I will omit it here. At this time,
Flask(__name__)
In this code, name is a variable that is defined arbitrarily. Contains the module name of the file. When the file is run directly as a script, name becomes main.
import Flask
In that case, the following code
flask.Flask(__name__)
It is easier to write from the beginning because you will have to specify.
'''python @app.route("/test")
`@app.route()`Is for associating a URL with a function. This is something that gets involved when you associate it with html etc., so you can't say anything by itself.
The rest of the code content is omitted because it is the basic part of python.
#at the end
I've just started myself, so please let me know if you make any mistakes.