简体   繁体   中英

IndentationError: expected an indented block [Python]

I got this very simple Python code, but somehow I always get an error:

IndentationError: expected an indented block

I checked all tabs and spaces twice and I can not find the mistake.

Can someone please give me a hint?

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!\n'

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

May be it is due the editor or improper indentation.

Your code is perfectly running in my pc but I would suggest to run the below code

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

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

For me worked this in the docker example.

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello World!'

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM