我正在尝试通过IIS发布Django Web应用程序(使用Python 2.7.15
创建)。首先,我安装了该应用程序:
:: 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
这时,我按照this指南配置IIS(我跳到了配置IIS以服务Django应用程序一章),但是最后,如果我浏览到{{3} }我收到此错误:
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:
谁能告诉我怎么了?
答案 0 :(得分:0)
您需要的只是 web.config
旁边的这个 manage.py
文件。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Django" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:\web\my-api\Scripts\python.exe|D:\web\my-api\Lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
</handlers>
</system.webServer>
</configuration>
还要确保您的站点在 IIS 中的 ApplicationPool
使用的是 LocalSystem
而不是 ApplicationPoolIdentity
。
其余的应该很容易设置。