I currently have a windows 2008 webserver running iis 7.5. I've successfully build PyISAPIe 1.1.0 for Python 2.7.4. Django is deployed and it works, fast. But as I know PyISAPIe is somehow old fashioned, last version release in 2010. I find out there are Helicon Zoo (WebPI packaged running WSGI bridge) and DjangoWindowsTools (automated deploy using Fascgi). So I would like to ask for your recommendation: which solution is best for django/python on IIS?
I can see you've found one solution. You may like to know that Helicon Zoo also support FastCGI protocol for operation (not related to Microsoft FCGI module). Additionally it supports TCP protocol (like Nginx on Linux) with is useful for comet and long polling support. Plus it offers many additional features that Microsoft FCGI module does not have, like automatic load balancing and application scaling, slow POST attack protection and many others. With Web Platform Installer and Helicon Zoo I could shrink your initial bat file. Please review:
rem Default settings
SET SITE_NAME=Django Site
SET SITE_PHYSIC_PATH=C:\intepub\%SITE_NAME%
SET SITE_URL=*
SET SITE_PORT=8000
SET SITE_PROTOCOL=http
SET SITE_NAME="Enter site name (%SITE_NAME%):" %=%
SET /p SITE_PHYSIC_PATH="Enter project directory, which contain manage.py (%SITE_PHYSIC_PATH%): " %=%
SET /p SITE_PROTOCOL="Enter http|https for protocol (%SITE_PROTOCOL%): " %=%
SET /p SITE_URL="Enter site url (%SITE_URL%):" %=%
IF "%SITE_URL%"=="localhost" (
SET SITE_URL="*"
)
ECHO.
ECHO Install IIS, Python, Helicon Zoo and other requirements if needed
WebpiCmd.exe /Install /Products:PythonModules /feeds:http://www.helicontech.com/zoo/feed/ /AcceptEula
ECHO.
ECHO Create IIS Site: %SITE_NAME%
md %SITE_PHYSIC_PATH%
%windir%\system32\inetsrv\appcmd add site /name:"%SITE_NAME%" /physicalPath:"%SITE_PHYSIC_PATH%" /bindings:%SITE_PROTOCOL%://%SITE_URL%:%SITE_PORT%
%windir%\system32\inetsrv\appcmd start site /site.name:"%SITE_NAME%"
ECHO.
ECHO Create Django application
echo ApplicationPath[@]%SITE_NAME%/>DjangoProject.app
WebpiCmd.exe /Install /Application:[email protected] /feeds:http://www.helicontech.com/zoo/feed/ /AcceptEula
This code can also install IIS, Python, Helicon Zoo and all other requirements on a complete clean system if needed. You will only need Web Platform Installer, which you can copy from other system where it is installed usually in C:\Program Files\Microsoft\Web Platform Installer No installation required.
Well, After another research I found out Windows Azure server use FastCGI and the setup pretty simple. No more download, build... You can see here http://www.windowsazure.com/en-us/develop/python/tutorials/web-app-with-django/
I've create a auto installer. It's working on Windows seerver 2008 r2 with iis 7.5. Just grap wfastcgi.py from here http://pytools.codeplex.com/releases
@ECHO OFF
rem Check for IIS setup
IF NOT EXIST %windir%\system32\inetsrv\appcmd.exe (
ECHO Please have IIS 7.5 install first
GOTO END
)
rem Default settings
SET PYTHON_EXE="C:\Python27\python.exe"
SET PROJECT_NAME="DjangoProject"
SET SITE_NAME="%PROJECT_NAME%"
SET SITE_PHYSIC_PATH=%~dp0
SET SITE_URL="*"
SET SITE_PORT="8000"
SET SITE_PROTOCOL="http"
SET DJANGO_SETTING="%PROJECT_NAME%.settings"
rem Gathering information
ECHO IIS 7.5 Django Setup
ECHO Author: James [email protected]
ECHO ===========================================
ECHO.
SET /p PYTHON_EXE="Enter python.exe path (%PYTHON_EXE%):" %=%
SET /p PROJECT_NAME="Enter project name (%PROJECT_NAME%):" %=%
SET SITE_NAME="%PROJECT_NAME%"
SET DJANGO_SETTING="%PROJECT_NAME%.settings"
SET /p SITE_PHYSIC_PATH="Enter project directory, which contain manage.py (%SITE_PHYSIC_PATH%): " %=%
SET /p DJANGO_SETTING="Django settings module (%DJANGO_SETTING%):" %=%
SET /p SITE_NAME="Enter IIS site name (%PROJECT_NAME%):" %=%
SET /p SITE_PROTOCOL="Enter http|https for protocol (%SITE_PROTOCOL%): " %=%
SET /p SITE_URL="Enter site url (%SITE_URL%):" %=%
IF "%SITE_URL%"=="localhost" (
SET SITE_URL="*"
)
SET /p SITE_PORT="Enter port (%SITE_PORT%):" %=%
SET WFCGI_FILE="%SITE_PHYSIC_PATH%\wfastcgi.py"
IF NOT EXIST %WFCGI_FILE% (
SET /p WFCGI_FILE="Please enter full path for wfastcgi.py: " %=%
)
ECHO =====================================
ECHO Installing
ECHO Install FASTCGI for IIS. Please wait.
start /wait %windir%\System32\PkgMgr.exe /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;IIS-StaticContent;IIS-DefaultDocument;IIS-DirectoryBrowsing;IIS-HttpErrors;IIS-HealthAndDiagnostics;IIS-HttpLogging;IIS-LoggingLibraries;IIS-RequestMonitor;IIS-Security;IIS-RequestFiltering;IIS-HttpCompressionStatic;IIS-WebServerManagementTools;IIS-ManagementConsole;WAS-WindowsActivationService;WAS-ProcessModel;WAS-NetFxEnvironment;WAS-ConfigurationAPI;IIS-CGI
ECHO.
ECHO Create IIS Site: %SITE_NAME%
%windir%\system32\inetsrv\appcmd add site /name:%SITE_NAME% /physicalPath:%SITE_PHYSIC_PATH% /bindings:%SITE_PROTOCOL%/%SITE_URL%:%SITE_PORT%:
%windir%\system32\inetsrv\appcmd start site /site.name:%SITE_NAME%
ECHO.
ECHO Setup Python FastCGI Handler
%windir%\system32\inetsrv\appcmd set config /section:system.webServer/fastCGI "/+[fullPath='%PYTHON_EXE%', arguments='%WFCGI_FILE%']"
ECHO.
ECHO Register the handler for this site
%windir%\system32\inetsrv\appcmd set config "%SITE_NAME%" /section:system.webServer/handlers "/+[name='Python_via_FastCGI',path='*',verb='*',modules='FastCgiModule',scriptProcessor='%PYTHON_EXE%|%WFCGI_FILE%',resourceType='Unspecified']" /commit:site
ECHO.
ECHO Configure the handler to run your Django application
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='%PYTHON_EXE%', arguments='%WFCGI_FILE%'].environmentVariables.[name='DJANGO_SETTINGS_MODULE',value='k6ecommerce.settings']" /commit:apphost
ECHO.
ECHO Configure PYTHONPATH so your Django app can be found by the Python interpreter
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='%PYTHON_EXE%', arguments='%WFCGI_FILE%'].environmentVariables.[name='PYTHONPATH',value='%SITE_PHYSIC_PATH%']" /commit:apphost
ECHO.
ECHO Tell the FastCGI to WSGI gateway which WSGI handler to use:
%windir%\system32\inetsrv\appcmd.exe set config -section:system.webServer/fastCgi /+"[fullPath='%PYTHON_EXE%', arguments='%WFCGI_FILE%'].environmentVariables.[name='WSGI_HANDLER',value='django.core.handlers.wsgi.WSGIHandler()']" /commit:apphost
ECHO.
ECHO Restart IIS
iisreset
ECHO Done...
:END
© 2022 - 2024 — McMap. All rights reserved.