-1

When I run my flask with pycharm python code run well but when it come to app.run() my terminal doesnot show any ip address it directly say unreachable code. I uninstall my python and pycharm and reinstall them the problem is same.I try with visual studio code but the error is same what can i do?enter image description here

  • Please remove extra two tabs from line number 7, then it should work. If you're new to python I suggest you to learn basics of python and then move to Flask – sattva_venu May 10 '21 at 14:52

1 Answers1

1

Your code is close but wrong. The error is because of the indentation. You have added the debug=True to the route, it should be indented from if __name__ == '__main__' like this:

from flask import Flask

app = Flask(__name__)

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

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

If you are curious about why you should bother with the addition of the if __name__ == '__main__': line then check out this great explanation.

Johnny John Boy
  • 3,009
  • 5
  • 26
  • 50