Answer the question
In order to leave comments, you need to log in
Why does the server immediately stop working when starting the server?
It was written in the documentation that by default it will start at 127.0.0.1:5000
But when the file is opened, it executes a function and the server stops working immediately and waits for the next command on the command line, and the file is not working.
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "hello world"
Answer the question
In order to leave comments, you need to log in
The code you provided doesn't run, just import the Flask class, set the app variable to an instance of the Flask class, and define a handler for the route. You should either change the documentation, or read it more carefully.
from flask import Flask
app = Flask(__name__)
@app.route("/")
def home():
return "hello world"
if __name__ == '__main__':
app.run()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question