Deploying a Django Web framework-based Python website app on IIS

Source: Internet
Author: User

Django is a Python-based web open-source framework that shows how to deploy a Django-written Python Web site to Windows IIS.

The author's operating environment:

    • Window XP SP3
    • IIS 5.1
    • Python 2.7.2 (http://www.python.org/)
    • pywin32-217.win32-py2.7 (Python's Win32 extension)
    • Django-1.3.1 (https://www.djangoproject.com/)
    • isapi_wsgi-0.4.2-py2.5 (http://code.google.com/p/isapi-wsgi/, WSGI implementation of the IIS-based ISAPI extension).
    • setuptools-0.6c11.win32-py2.7

Explanation of principle:

With ISAPI, IIS can extend Web applications that support other language implementations, and isapi_wsgi-0.4.2-py2.5 this program implements the WSGI specification as an ISAPI.

The WSGI specification is a specification of the interface between a Python Web application and a Web service container, through which a request to a virtual site of IIS can be directed

To this ISAPI, without having to change any of the Python web code in order to deploy to a particular container.

Steps

    1. It's easy to install IIS, Python, Django, Setuptools, and Pywin32 first. (Add the environment variable path to the Python installation home directory)
    2. Download the Isapi_wsgi-0.4.2-py2.5.egg file (this is a Python install package, similar to Red Hat rpm, of course you can also download exe or zip download installation)
    3. After downloading, enter in the command line window: Easy_install Isapi_wsgi-0.4.2-py2.5.egg (Here it will prompt you to install successfully, note: You must install Setuptools to run the command)
    4. Write a deployment script with the name assumed to be wsgi_deploy.py (assuming your Web project directory is C:\Web, there is an app for MySite in the web directory), the directory must not be mistaken, otherwise it is prone to HTTP 500 error.

Import OS, sys sys.path.append (' c:\\web ') os.environ[' django_settings_module '] = ' mysite.settings '

Import DJANGO.CORE.HANDLERS.WSGI application = Django.core.handlers.wsgi.WSGIHandler ()

Import Isapi_wsgi # The entry points for the ISAPI extension. Def __extensionfactory__ (): Return ISAPI_WSGI. Isapisimplehandler (Application)

If __name__== ' __main__ ':     # If Run from the command-line, install ourselves.     from isapi.install import *     params = isapiparameters ()     # Setup th E virtual Directories-this is a list of directories we     # extension uses-in this case only 1.     # Each extension have a "script map"-This is the mapping of the ISAPI     # extensions.     sm = [        scriptmapparams (extension= "*", flags=0)     ]     VD = virtualdirparameters (name= "MySite",                                 Description = "Isapi-wsgi isapisimplehandler Django mysite",     & nbsp;                         scriptmaps = SM,                                 scriptmapupdate = "Replace"                                )     params. Virtualdirs = [VD]     handlecommandline (params)

5. In the command line input: wsgi_deploy.py install, after the run will create the above script definition of the virtual path "MySite", and you will find a ' _wsgi_deploy.dll ' file will be created, this is the ISAPI.

A careful reader may wish to check the settings of the IIS "MySite" to see it.

 

6. After deployment, you can access your web app from a browser

Note: If an error occurs, how do I handle it?

You can enter at the command line: python-m win32traceutil to output error stack information for ISAPI_WSGI module output

Usually, errors occur in the path aspect. As similar to

Importerror:could not import Settings ' Mysite.settings ' (Was it on Sys.path?): N o module named mysite.settings such a problem.

In this case, you need to find the above deployment script wsgi_deploy.py, go to the correct configuration, and then remember to run it first

wsgi_deploy.py Remove and then run wsgi_deploy.py install.

Reference: http://code.google.com/p/isapi-wsgi/

Deploying a Django Web framework-based Python website app on IIS

Related Article

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.