-1

I've below code executed in a virtualenv on Linux:

# import the Flask class from the flask module
from flask import Flask, render_template

# create the application object
app = Flask(__name__)

# use decorators to link the function to a url
@app.route('/')
def home():
    return "Hello, World!"  # return a string


# start the server with the 'run()' method
if __name__ == '__main__':
    app.run(debug=True)

Execution output:

* Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

But unable to open the server on any browser using: http://localhost:5000/

Any help?

User123
  • 1,328
  • 2
  • 11
  • 25
  • "But unable to open the server on any browser using: http://localhost:5000/" what *exactly* does that mean? Do you get an error page in the browser? Anything in the Javascript console? What does the network inspector say? Have you tried adding a print statement to your flask route and checking the terminal to see if the request is coming through? Etc. etc. – Jared Smith Jan 01 '22 at 18:56

1 Answers1

-2

try 127.0.0.1:5000 instead of localhost:5000

if not worked again, use:

if __name__ == '__main__':
    app.run(host="0.0.0.0", port=5000)

and go for http://0.0.0.0:5000


Also try to check for the port 5000, is it open? is it specified to another service?

netstat -pnlt | grep ':portno'

more info can find here about above command

if port 5000 was specified to another service, you can change the port in flask or kill that service by kill -9 <PID> and port 5000 will be available again.

Ali
  • 118
  • 1
  • 2
  • 8
  • 1
    0.0.0.0 makes sense as an address to _listen_ to (it selects every possible actual IP address), but it does not identify a valid address to connect to. – tripleee Jan 01 '22 at 19:52
  • 1
    Also, don't routinely use `kill -9` – tripleee Jan 01 '22 at 19:53
  • 0.0.0.0 is actually work, also here is not a placed to talk about linux commands and their use cases, so its not make sense to describe a linux command (kill) and its use cases... i just suggested some solutions that actually works... – Ali Jan 02 '22 at 06:00
  • 1
    You suggested `kill -9` but the correct suggestion is `kill`; how is that not relevant here? – tripleee Jan 02 '22 at 10:01