Creating and running demo flask app in VS Code | Flask in Visual Studio Code Tutorial Part #2
8.3 هزار بار بازدید -
2 سال پیش
-
We have already done the
We have already done the Flask dev environment setup for VS Code in Tutorial Part -1: Flask installation and setup in Visua...
In Flask tutorial part #1, we have created the folder hello_flask, that folder is opened in Visual studio code as you can see here.
Let's create an app and then start a server then we run the app from the browser.
Step 1: create a new file with the name, app.py and save it.
Step 2: Now we write the following lines of code in this file --
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello, Flask!"
save the app.py file (Ctrl+S).
Step 3: Now Run the flask server by using a terminal with the command -
python -m flask run
which runs the Flask development server. The development server looks for app.py by default.
note: If you see an error that the Flask module cannot be found,
then run the following command: python -m pip install flask
and restart VS Code once.
Step 4: Also, if you want to run the development server on a different IP address or port, use the host and port command-line arguments, as with --host=0.0.0.0 --port=80.
Step 5: Run the app from the browser.
Step 6: Stop the app by using Ctrl+C in the terminal.
#RunFlaskAppVSCode #coolithelp
In Flask tutorial part #1, we have created the folder hello_flask, that folder is opened in Visual studio code as you can see here.
Let's create an app and then start a server then we run the app from the browser.
Step 1: create a new file with the name, app.py and save it.
Step 2: Now we write the following lines of code in this file --
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "Hello, Flask!"
save the app.py file (Ctrl+S).
Step 3: Now Run the flask server by using a terminal with the command -
python -m flask run
which runs the Flask development server. The development server looks for app.py by default.
note: If you see an error that the Flask module cannot be found,
then run the following command: python -m pip install flask
and restart VS Code once.
Step 4: Also, if you want to run the development server on a different IP address or port, use the host and port command-line arguments, as with --host=0.0.0.0 --port=80.
Step 5: Run the app from the browser.
Step 6: Stop the app by using Ctrl+C in the terminal.
#RunFlaskAppVSCode #coolithelp
2 سال پیش
در تاریخ 1401/07/14 منتشر شده
است.
8,379
بـار بازدید شده