Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serving Flask app with waitress on windows

I am able to run a webserver using the following code

from flask import Flask
from waitress import serve

app = Flask(__name__, static_url_path='/static')
...
serve(app, port=8080)

The problem is that I can access it only from the machine where it is running, if I try to access it using the ipv4 ip, it doesn't work. Am I missing a step?

like image 524
llulai Avatar asked Jun 26 '18 14:06

llulai


People also ask

How do I host Flask app on Windows server?

Inside FlaskApp folder, create the Flask Application file “app.py”. Now, copy the “wfastcgi.py” file from “C:\Python\Lib\site-packages\” directory and paste it to “C:\inetpub\wwwroot\FlaskApp\” directory. Now, as the permissions are added, we are ready to deploy our Flask application in the IIS server.

How do I run Flask app on Windows?

To run the app outside of the VS Code debugger, use the following steps from a terminal: Set an environment variable for FLASK_APP . On Linux and macOS, use export set FLASK_APP=webapp ; on Windows use set FLASK_APP=webapp . Navigate into the hello_app folder, then launch the program using python -m flask run .

How do you use a waitress in a Flask?

The only required argument to waitress-serve tells it how to load your Flask application. The syntax is {module}:{app} . module is the dotted import name to the module with your application. app is the variable with the application.


3 Answers

Simple example,try it!
I hope it will help you.

app1.py

from flask import Flask app = Flask(__name__) # app.run(host='0.0.0.0', port=8080,debug=True) 

waitress_server.py

from waitress import serve import app1 serve(app1.app, host='0.0.0.0', port=8080) 

Then run below command

python waitress_server.py  
like image 58
Dondon Jie Avatar answered Sep 23 '22 19:09

Dondon Jie


Waitress now provides a simple command line Utility called waitress-serve for running the Flask Application. Please note that this answer is valid for Waitress 1.30. The command line arguments could change in future.

If your Flask application is called myapplication and the method which instantiates your application is called create_app, then you can simply use:-

waitress-serve --call "myapplication:create_app"

This command will launch the server listening on port 8080 by default.

If you wish to launch it on port 80 (http), then all you need to do is:

waitress-serve --port=80 --call "myapplication:create_app"


enter image description here NB: click on the image if it's not very clear.

Waitress serve command line arguments.

Flask 1.0 production deployment tutorial.

like image 28
Adithya Upadhya Avatar answered Sep 22 '22 19:09

Adithya Upadhya


Try using

serve(app, host='0.0.0.0', port=8080)
like image 29
user2218085 Avatar answered Sep 21 '22 19:09

user2218085