Python Flask WebAPI - chanandrew96/MyLearning GitHub Wiki
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
Execute the flask python file:
flask --app [python filename] run
- Open "Turn Windows Feature on or off" and enable "CGI' under "IIS/WWW Services/Application Development Features"
- Execute
pip install wfastcgi
to install wfastcgi - Go to your Python\Scripts folder
You may find the Python folder location bywhere python
Then execute the wfastcgi-enable.exe
Or you may executewfastcgi wfastcgi-enable
to enable wfastcgi
Add Permission for IUSR in order for IIS to access your application folder
icacls . /grant "NT AUTHORITY\IUSR:(OI)(CI)(RX)"
icacls . /grant "Builtin\IIS_IUSRS:(OI)(CI)(RX)"
Or you can add permission using the GUI
Search user "IUSR" and "IIS_IUSRS" and grant the permission
When wfastcgi enabled, you should able to find the "FastCGI Settings" in your IIS root
In your Site Application, open "Handler Mappings" page and select "Add Module Mapping..." on Actions
Request path: * Module: FastCgiModule Executable (optional): [YOUR_PYTHON_EXE_PATH]|[YOUR_WFASTCGI_EXE_PATH] Name: FlaskHandler
Click the "Request Restrictions..." button Uncheck the "Invoke handler only if request is mapped to:" checkbox
Back to the IIS root FastCGI Settings, and you should able to see record which "Full Path" and "Arguments" defined with your Python and wfastcgi path
Double click to Edit the record
Edit the Environment Variables under FastCGI Properties
Create 2 new members Name: PYTHONPATH Value: [YOUR_APPLICATION_ROOT_FOLDER] Name: WSGI_HANDLER Value: [YOUR_ENTRY_PY_FILE_NAME].app
Deploy a Python Flask Application in IIS Server and run on machine IP address
IIS部署python Web 使用Flask
如何將 Django 架設在 IIS 上