首页|资源下载
登录|注册

您现在的位置是:首页 > 技术阅读 >  如何在 IIS 中执行 Python 脚本

如何在 IIS 中执行 Python 脚本

时间:2024-05-13

如何在 IIS 中执行 Python 脚本

Python 是一种解释脚本语言,概念类似 Microsoft Visual Basic ScripTIng EdiTIon (VBScript)、 MicrosoftJScript、 Perl, 或其他脚本语言。 对于 AcTIve Server Pages (ASP) 以及简单通用网关接口 (CGI) 脚本,IIS使用 WindowsScripTIngHost 解析VBScript 和 JScript , IIS 可以使用其他脚本解释程序。 本文介绍如何使用 Python 作为脚本语言是选择用于 CGI 和 ASP。

  在IIS管理器“网站”节点上点击右键,选择“属性”“主目录”,点击“配置”按钮,在“映射”中点击“添加”,在对话框中将“可执行文件”设置为“〈python安装目录〉/python.exe %s %s”,扩展名为“.py”,动作为“全部动作”,然后点击确定。

  IIS现在就能解析py了吗?编写一个test.py文件:

  print  print ’Status: 200 OK’  print ’Content-type: text/html’  print

  print ’〈HTML〉〈HEAD〉〈TITLE〉Python Sample CGI〈/TITLE〉〈/HEAD〉’  print ’〈BODY〉’  print ’〈H1〉This is a header〈/H1〉’  print ’〈p〉’ #this is a comment  print ’See this is just like most other HTML’  print ’〈br〉’  print ’〈/BODY〉’

  如果使用IIS访问,类似http://localhost/test.py,显示内容为:

  This is a header  See this is just like most other HTML