flask 'hello world' not working

Viewed 27461

I copy pasted the flask's 'hello world' app from their website and am trying to run it. I get an error message in Chrome saying

Internal Server Error

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

Here is the 'hello world' app straight from flasks website

from flask import Flask
app = Flask(__name__)

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

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

What I have tried:

-temporarily disabling Avast!

-disabling windows firewall

-ensuring that the flask module is installed

This was working a couple days ago actually...

7 Answers
from flask import Flask

app = Flask(__name__)


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


if __name__ == '__name__':
    app.run()

app.run(port=5000)

For Windows machines you can use the command in cmd:

set FLASK_APP=python_file.py
flask run

I think you are trying to copy the route generated through your flask program in cmd by pressing ctrl+c which quits your running flask program . i was also doing the same.just try to type the route generated by your flask program on your browser . it will definitely resolve your problem.

Where your python file store is, use cmd and then go on your file store directory, then

set FLASK_APP=filename.py

After this your flask run cmd will work.

   from flask import Flask
   app = Flask(__name__) # creating app
   @app.route('/', methods['GET']) #routing it to the home page
   def home(): #function
       return "hello world"
   app.run(port=5000, debug=true) #function call by the app

Add port and use methods whatever your need is USE GET in your case and try to remove your cache and run the this code it will definitely work.

Related