首页 > 解决方案 > 配置 IIS 以服务 Django 应用程序

问题描述

我正在尝试Python 2.7.15通过 IIS 发布一个 Django Web 应用程序(使用创建的)。首先我安装了应用程序:

:: setup folders
mkdir C:\Software\MyApp\
cd C:\Software\MyApp\

:: clone the git Repository
git clone https://gitlab.com/blablabla.git C:\Software\MyApp\MyAppServer

:: create the virtualenv
python -m pip install --upgrade pip
pip install virtualenv
virtualenv py2_env
call py2_env\Scripts\activate.bat

:: install the python-requirements in the virtualenv
pip install -r C:\Software\MyApp\MyAppServer\requirements.txt

:: copy all static files in C:\var\www
python C:\Software\MyApp\MyAppServer\manage.py collectstatic

:: just to check if the app works (and it works!)
python C:\Software\MyApp\MyAppServer\manage.py runserver

此时,我的文件夹组织是:

C:\
└── Software\
    └── MyApp\
        ├── py2_env\
        │   ├── Include\
        │   ├── Lib\
        │   ├── Scripts\
        │   └── tcl\
        └── MyAppServer\
            ├── manage.py
            ├── ...
            └── myapp_django_server\
                ├── urls.py
                ├── wsgi.py
                └── ...

我的py2_env虚拟环境中安装的软件包是:

(py2_env) C:\Software\MyApp\py2_env\Scripts>pip freeze --local
Django==1.11.2
djangorestframework==3.6.3
numpy==1.12.1
pytz==2018.7
wfastcgi==3.0.0

此时,我按照指南配置 IIS(我跳到了配置 IIS 以服务 Django 应用程序一章),但是最后,如果我浏览到http://localhost:81,我会收到此错误:

Error occurred:

Traceback (most recent call last):
  File "C:\Software\EVARplanning\py2_env\Lib\site-packages\wfastcgi.py", line 847, in main
    result = handler(record.params, response.start)
TypeError: get_wsgi_application() takes no arguments (2 given)


StdOut: 

StdErr:

谁能告诉我怎么了?

标签: djangoiiswsgifastcgi

解决方案


问题出在我WSGI_HANDLER的 IIS 中FastCGI Settings。我将它的值从django.core.wsgi.get_wsgi_applicationto转换为django.core.wsgi.get_wsgi_application()然后它可以工作。


推荐阅读