0

I'm trying to run the Hello World using Flask framework :

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello() -> str:
    return 'Hell world from Flask!'
app.run()

Then I go to my cmd and I run my script according to the documentation:

set FLASK_APP = flaskhello.py
python -m flask run 

And what I get is a grey window with a click me header and when I click it i get the X and Y but I don't get the http address on my cmd to run it on browser. What should I do to correct this ?

I've already installed flask correctly as it seems, but I'm not sure.

edit. I also tried creating a new venv and the same happens

dungeon
  • 41
  • 10

2 Answers2

4

You are mixing old and new documentation. You can lose the last line in flaskhello.py (app.run()). Then, don't pass the flask run command to python, but run it directly in the CMD. So not python -m flask run, but flask run.

Imre_G
  • 2,468
  • 1
  • 17
  • 33
  • The same thing happens there's no console for the http address – dungeon Aug 04 '19 at 11:40
  • I just removed every old python file from my directory and now it seems to be working fine I don't know what was the issue exactly but some file was interfering with flask. Thanks both of you – dungeon Aug 04 '19 at 13:24
1

I've tested your code and it is serving a page with Hell world from Flask!, are you sure your flask servers starts, do you see the following in the console:

 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [04/Aug/2019 13:35:44] "GET / HTTP/1.1" 200 -

Starting with Flask 0.11 there are multiple built-in ways to run a development server. The best one is the flask command line utility (https://flask.palletsprojects.com/en/1.1.x/server/)

export FLASK_APP= flaskhello.py
flask run

enter image description here

dejanualex
  • 3,872
  • 6
  • 22
  • 37