Creating and running demo flask app in VS Code | Flask in Visual Studio Code Tutorial Part #2

preview_player
Показать описание

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 2: Now we write the following lines of code in this file --
from flask import Flask
app = Flask(__name__)

def home():
return "Hello, Flask!"


Step 3: Now Run the flask server by using a terminal with the command -
python -m flask run

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
Рекомендации по теме
Комментарии
Автор

wow, after much distress and frustration trying to get my flask to work. I finally found exactly what I was looking for. my flask app works!!!. Thank you for this great tutorial for both Part 1 and Part 2

rroctb
Автор

bro you are awesome, i was stuck in some where could not able to run flask, it helped me a lot, thank you

ashutoshtinker
Автор

tip: if you dont want to restart the server every time use this command to launch: python -m flask --debug run

ansh
Автор

this is exactly what i have been looking for, thank you

otd
Автор

Failed to find Flask application or factory in module 'app'. Use 'app:name' to specify one got this error

_ankit_
Автор

the code didn't run for me
but when i added this:

if __name__ == '__main__':
app.run(debug=True)

it ran well anyway

why would this happen?

anyone could tell me the reason?

wirayogie