As wfastcgi module is not compatible with Python 3.7, What is the best way to host a python flask application on a Windows Server?
How to Host Your Flask App on PythonAnywhere for Free Step 1: Create a requirements.txt. Create a new file in your project directory called requirements.txt. Make sure the... Step 2: Create a PythonAnywhere account. This will allow you to create a free account. After clicking that, you will be... ...
from flask import Flask app = Flask (__name__) @app.route ("/") def hello (): return "Hello from FastCGI via IIS!" if __name__ == "__main__": app.run () now open iis. right-click on the server name and select add site. enter the site name physical path and the site binding.
In the production environment, you can not use Flask to host your API and you definitely need a production web server like Apache or Gunicorn. Flask is good for development purposes but when you move to production you need to host it on the Web server. Here is an example of Architecture where it can be helpful. Step 1.
Open Visual Studio and click on Create a new project. Find the Flask Web Project template, name it and click Create. This code runs the local development server which defines the default Flask port that it will be using along with the host to use IP addresses on the local machine.
you need to install the python,wfastcgi, and flask at your server.
You can download the python from below link:
https://www.python.org/downloads/
after installing python download the wfastcgi:
pip install wfastcgi
run the command prompt as administrator and run this command.
wfastcgi-enable
run this command to enable wfastcgi.
below is my flask example:
app.py:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello from FastCGI via IIS!"
if __name__ == "__main__":
app.run()
after creating an application to run it use below command:
python app.py
now enable the cgi feature of iis:
executable path value:
C:\Python37-32\python.exe|C:\Python37-32\Lib\site-packages\wfastcgi.py
Note: Do not forget to assign the iusr and iis_iusrs user permission to the flask site folder and python folder.
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