Reputation: 21
I am using Windows 10 Home.I have Python 3.9.1 and Visual Studio Code.I am studying to Flask in Visual Studio Code. I just want to run this code:
from flask import Flask
app =Flask(__name__)
@app.route("/")
def index():
return "Home Page"
index()
After I open the terminal and I write 'python hello.py(hello is my files name)'.But It doesn'work.Nothing happens when I press ent, we just skip a line.
What should I do?
Upvotes: 1
Views: 40
Reputation: 14233
Change your code like this:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def index():
return "Home Page"
if __name__ == "__main__":
app.run()
when you run this script in terminal you will see some information when it starts development server, e.g.
* Serving Flask app "hello" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [26/Mar/2021 13:30:48] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [26/Mar/2021 13:30:48] "GET /favicon.ico HTTP/1.1" 404 -
Now, open your browser and go to http://127.0.0.1:5000/
Note, there are different ways to structure and run your flask app, please refer to docs or tutorial..
Upvotes: 2