-1

I am trying to make a simple flask app using putty but it is not working

here is my hello.py file:

from flask import Flask

app = Flask(__name__)

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

command I am running in putty (when in the file directory of hello.py)

pip install flask

python -c "import flask; print(flask.version)"

Output:1.1.2

export FLASK_APP=hello

export FLASK_ENV=development

flask run

when I go to the ip address: http://127.0.0.1:5000/

I get this enter image description here

also here is the link of the instruction I am following/did: https://www.digitalocean.com/community/tutorials/how-to-make-a-web-application-using-flask-in-python-3

if someone could let me know how to make it work would be great! thank you!

mpl
  • 35
  • 1
  • 5
  • 1
    If you're working in putty, that suggests you're running flask or a remote machine, not your local one. The IP address 127.0.0.1 refers to your local machine. – joanis May 01 '21 at 20:19
  • 1
    You might need to either run a browser on that remote machine, or change the IP to the name or IP of that remote machine in your local browser. – joanis May 01 '21 at 20:21
  • Please check this answer: [link](https://stackoverflow.com/questions/7023052/configure-flask-dev-server-to-be-visible-across-the-network). set this `app.run(host="0.0.0.0")`. However, you have to enter the IP address of the remote server/computer etc, which you should see on putty as well. Then, you can enter this IP address to server with port id. – m.i.cosacak May 01 '21 at 21:30

2 Answers2

0

I used my terminal on my window machine instead of putty which is a remote machine

mpl
  • 35
  • 1
  • 5
-2

Check your wlan0 inet adress by typing ifconfig in bash and use it, also try to add the following code in your flask app:

if __name__ == '__main__':
    app.run(debug=True, port=5000, host='wlan0 IP Add')

Run the application by typing >>sudo python3 hello.py

Did this work?

Matt Brown
  • 11
  • 2
  • 1
    I don't see how this is related - localhost should always work, regardless of his lan/wifi/whatever IP address... Also, `flask run` is preferred over `app.run()` and **DO NOT RUN THIS AS ROOT** (sudo) – ThiefMaster May 01 '21 at 20:38
  • Thank you for the replies! I went in my terminal instead of putty and it work! – mpl May 01 '21 at 21:54
  • If you are not sure, never run sudo as suggested by @ThiefMaster. If you want to deploy your flask app, there are several ways to run it or simply ask on SO. – m.i.cosacak May 02 '21 at 19:19