I
I
Ingerniated2018-01-17 17:02:49
Flask
Ingerniated, 2018-01-17 17:02:49

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

1 answer(s)
S
Sergey Gornostaev, 2018-01-17
@Ingernirated

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 question

Ask a Question

731 491 924 answers to any question