Deploy Django & amp; Flask, wfastcgiiisdjango in IIS with wfastcgi

Source: Internet
Author: User

Deploy Django & Flask, wfastcgiiisdjango in IIS with wfastcgi

Django and Flask can be conveniently deployed in FastCGI mode under Linux. It seems that the configuration below IIS is not good, and IIS also lacks a fully automatic configuration tool like PHPmanager, the deployment on the company's servers is quite complex. After the deployment, the process is not complicated. The main reason is that no complete solution is provided on the Internet. Here we record it for your convenience.

Let's start with Django. Simply open a testing website on your machine. Here I use "C: \ myWebSite \ djangoWeb" for testing.

Add a Hello world homepage and test whether it works normally.

Install wfastcgi module with pip

The important step is to go to the site-package directory in python.

Copy the "wfastcgi. py" file to the root directory of the website.

I will describe the specific cause, and now go to IIS to add a website

You must enter the "handler ing" in the website console. Do not go to the IIS console directly. Otherwise, the created FastCGI will take effect for all websites.

Click "add module ing" on the right. The details are as follows:

Enter the location of "python program" and "wfastcgi. py" in the executable file column, and enter the name at will. Do not forget the "|" symbol in the middle.
After entering this information, open the request restriction and check "the handler is called only when the request is mapped to the following content"

After adding the application, the create FastCGI application dialog box is displayed. Click OK to create the application.

In this way, you can see the newly added FastCGI ing in the handler ing.

Return to the IIS console and go to "FastCGI Settings". You can see the newly added ing.

Double-click to open and add environment variables for Django execution

There are three environment variables:

WSGI_HANDLER is django. core. handlers. wsgi. WSGIHandler ()
PYTHONPATH is the website root directory
DJANGO_SETTINGS_MODULE is the location of the django settings file

Restart IIS or recycle it in the application pool.

Test whether it works normally.

So far, Django has been deployed.

If an error occurs, test "MIDDLEWARE_CLASSES" and "INSTALLED_APPS" one by one in settings. compatibility problems may occur in some cases.

Then deploy Flask. Create a website and copy "wfastcgi. py ".

The Flask initialization code is very short. Just test whether the website works normally.

Create a website and add a ing.
Note the file path of "wfastcgi. py" when adding the ing

Confirm after adding

Return to the IIS console and go to "FastCGI Settings". We can see two "FastCGI ing". We can infer that IIS will create different mappings for different parameters of the same execution program.

I tested it. If you only call the same "wfastcgi. py file, you will not be able to create different FastCGI execution environments for different websites, that is why the "wfastcgi. the reason why the py file is copied to the website directory

Add Environment Variables

Flask deployment only requires two environment variables:

WSGI_HANDLER corresponds to the location of the Flask instance. Here is the app in the flaskWeb file.
PYTHONPATH is the website root directory

After the configuration is complete, restart IIS or recycle the corresponding process.

The test is successful. Flask has been deployed.

Next, let's take the static file processing method as an example. The "static" folder in the Flask project does not need to be set too much.

Find the folder in IIS and open the handler ing.

The list here is consistent with the website

Delete the FastCGI ing created for the website, and the static folder can be accessed directly. The "Restore to parent" on the right can be used to restore the modification to this directory.

In order to test whether I enabled directory browsing for this directory, I put a jQuery

I seem to have a problem with IE. For Chrome, jQuery files can also be viewed directly.

The static file problem has been solved here. If you access other locations through the virtual directory, you can perform the same operation.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.