IIS没有用PyISAPI链接到Django

2024-04-25 17:28:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试在基于IIS的服务器上运行一个带有Django的站点。我遵循了主站点(http://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer)上的所有说明,并用一篇非常好的文章(http://www.messwithsilverlight.com/2009/11/django-on-windows-server-2003-and-iis6/)对其进行了复查。在

我成功地设置了IIS来读取.py文件。按照主要说明,我可以让服务器呈现信息py. 然而,我似乎不能让IIS和Django玩得很好。例如,如果我的虚拟目录是“abc”,那么如果我转到“localhost/abc/”,浏览器只会显示该文件夹的内容目录。此外,如果我的url设置为“/dashboard/1”应该将我带到某个页面,那么输入“localhost/abc/dashboard/1”会给我一个“页面无法显示”的错误。在

我相当肯定IIS根本没有引用Django或与Django交互。有人知道怎么解决这个问题吗?在

谢谢


Tags: djangopy服务器comlocalhosthttp站点wiki
2条回答

这是我遵循的最初指示

基本说明:https://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer 附加提示:http://whelkaholism.blogspot.ca/

  1. 首先应该安装Python2.5或2.6,对于2.7,您需要重新编译PyISAPIe,这我还没有做过。http://www.python.org/ftp/python/2.6/python-2.6.msi
  2. 您需要安装与Python解释器版本匹配的PyISAPIe版本,如果不匹配,它将失败。去那里:http://sourceforge.net/projects/pyisapie/files/pyisapie/
  3. 将最后一步提取的文件夹移到适当的位置(例如C:)
  4. 您需要更改的安全设置PyISAPIe.dll,他们建议网络服务阅读,但我设置了所有人,以确保这没有问题
  5. 然后,您必须将pyisapi的Http文件夹剪切并粘贴到Python安装目录的Lib\Site包中(重要)
  6. 接下来,设置IIS(在run(winkey+r)中使用inetmgr打开管理器:
    • 添加新的虚拟目录并允许在向导提示时执行ISAPI扩展
    • 在虚拟目录的属性中添加新的通配符扩展名,取消选中文件存在设置
    • 将Web服务扩展添加到指向dll的IIS管理器,确保允许它
  7. 从PyISAPIe文件夹中,复制examples\django\Isapi.py并将其粘贴到Lib\Site Packages\Http中
  8. 在Isapi.py,设置路径(即c:\inetpub\wwwroot\web_site\django_project)和DJANGO_SETTINGS_模块(即django_app.SETTINGS)
  9. 对文件进行任何更改时,请在命令提示符下使用iisreset应用更改

下面是一些你可以做的事情

  • 确保db文件的路径(如果使用了sqlite)是正确的
  • 对模板位置设置执行相同的操作
  • 在您的url和html文件中,确保路径以您给虚拟目录别名的名称开头(例如,在我们的示例中,web_site

最后,在服务CSS时可能会遇到困难。如果有任何问题,请告诉我。在

向任何Web服务器提供Django基本上涉及三个关键细节:

  1. 告诉网络服务器,“我想要你 提供服务 这个调用python的模块“
  2. 告诉python模块,“我希望您执行python代码 使用此文件中的详细信息“
  3. 告诉档案,“我要你用Django”

如果您要获取虚拟目录的目录列表,那么您应该调查VD设置,以确保为该目录配置了PyISAPIe(key details#1)。在

从你提到的文章中:

  • Open the IIS Management Console, and create a new virtual directory, and allow executing ISAPI extensions when prompted by the wizard.

    • View the properties of the new folder and click on the "configuration" button (if it's greyed out, click 'create' first), then add a new wildcard extension (the lower box), locate the pyisapie.dll file and untick the "check that file exists" box.

    • In the IIS Manager, go to the "Web Service Extensions" section, and right click -> add new web service extension.

  • Give it a name (it doesn't matter what), add the pyisapie.dll fill as a required file and check the box to set the extension status to allowed.

相关问题 更多 >