1

I am new to using Flask. Tried to run the basic flask app but results in neither an error nor any output. Can anyone help me to resolve the same?

Code:

from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello, World!"

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

console:

 * Serving Flask app "__main__" (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: on

I'm not getting *Running on http://127.0.0.1:5000/ (press ctrl+c to quit).

Can anyone help me on this, please?

5
  • Are you getting any errors? Show us your code? Commented Dec 1, 2019 at 8:05
  • from flask import Flask app = Flask(name) @app.route("/") def hello(): return "Hello, World!" if name == 'main': app.run(debug=True, use_reloader=False) Commented Dec 1, 2019 at 8:23
  • @srikanth Chekuri I have commented the code above Commented Dec 1, 2019 at 8:23
  • I am not getting any errors Commented Dec 1, 2019 at 8:24
  • 2
    Did you, perchance, open your web browser and go to 127.0.0.1:5000 ? What message came up in the browser? Commented Dec 1, 2019 at 20:56

2 Answers 2

1
app = Flask(__name__) 

You forgot the underscores.

if __name__ == '__main__':
    app.run()
Sign up to request clarification or add additional context in comments.

5 Comments

It is very unlikely that this was the error. Because the missing underscores came from a wrongly formatted question. It is now fixed.
How is it fixed? Why not share if you know what could cause it? My guess was that the wrongly formatted question was also the way the code was written.
Oh, I didn't mean the issue was fixed, just the formatting of the question. The missing underscores could not be the problem anyway, because name (without underscores) is not defined in the namespace and therefore a NameError would be thrown. But since no syntax error was thrown in the output of the python script, it rules out a solution that refers to missing underscores.
hi, thanks for your response.I was facing the issue using jupyter notebook but the issue was fixed when I ran the same code in Visual Studio Code,
@AnnMary - you can answer and accept your own question if you want (if this was the problem and the solution, of course).
0
from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello, world!"

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

Please compare your own code with mine, there were some things you left out.

1 Comment

This is a very vague answer, where extra effort has to be done to see what your changes are. It is also very unlikely that this was the error. Because the missing underscores came from a wrongly formatted question. It is now fixed.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.