laiakini
laiakini

Reputation: 31

python flask to production server

I have made a small API to connect to a database using Flask.

When I run it I get this output on local (which works fine in postman)

 * 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: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

I want to run this file (main.py) on a server that I have at 172.22.98.254. But when I run it there it still gives me this output:

 * 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: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)

So, when I use my postman doing this

enter image description here

where my post URL is http://172.22.98.254:5000/test, How can I use this from the server that I have. I have an ubuntu server.

Upvotes: 0

Views: 14739

Answers (2)

Kumar Sanjay
Kumar Sanjay

Reputation: 21

I have changed the host default ip address to server or Local network computer ip address. it works fine. My local ip address is 192.168.1.34, using same port as 5000.

app.run(host='192.168.1.34', port=5000)

Upvotes: 1

pu2x
pu2x

Reputation: 111

By default, app.run() hosts server on localhost(127.0.0.1). To make it accessible,

app.run('0.0.0.0', port=5000)

Although, the server bundled with Flask is not for production, it is recommended to use WSGI server(mod_wsgi, nginx, gunicorn, etc.)

https://flask.palletsprojects.com/en/1.0.x/deploying/wsgi-standalone/

Upvotes: 4

Related Questions