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?
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.
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 .
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.
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
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"
NB: click on the image if it's not very clear.
Waitress serve command line arguments.
Flask 1.0 production deployment tutorial.
Try using
serve(app, host='0.0.0.0', port=8080)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With