Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to host Python 3.7 flask application on Windows Server?

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?

like image 949
Ishan Avatar asked Oct 06 '19 21:10

Ishan


People also ask

How to host your flask app on PythonAnywhere for free?

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... ...

How do I run a flask app from FastCGI via IIs?

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.

Can I use flask to host an API?

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.

How do I use flask in Visual Studio Code?

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.


1 Answers

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()

enter image description here

after creating an application to run it use below command:

python app.py

now enable the cgi feature of iis:

enter image description here

  • now open iis.
  • right-click on the server name and select add site.
  • enter the site name physical path and the site binding.
  • after adding site select the site name and select the handler mapping feature from the middle pane.
  • Click “Add Module Mapping” enter image description here
  • add below value:

enter image description here

enter image description here

enter image description here

executable path value:

C:\Python37-32\python.exe|C:\Python37-32\Lib\site-packages\wfastcgi.py

  • Click “Request Restrictions”. Make sure “Invoke handler only if request is mapped to:” checkbox is unchecked:

enter image description here

  • Click “Yes” here:

enter image description here

  • now go back and again select the server name and select fast CGI setting from the middle pane.

enter image description here

  • Double click it, then click the “…” for the Environment Variables collection to launch the EnvironmentVariables Collection Editor:

enter image description here

  • Set the PYTHONPATH variable:

enter image description here

  • And the WSGI_HANDLER (my Flask app is named app.py so the value is app.app — if yours is named site.py it would be site.app or similar):

enter image description here

  • Click OK and browse to your site:

enter image description here

Note: Do not forget to assign the iusr and iis_iusrs user permission to the flask site folder and python folder.

like image 200
Jalpa Panchal Avatar answered Nov 15 '22 09:11

Jalpa Panchal