Python是一種解釋腳本語(yǔ)言,概念類似 Microsoft Visual Basic Scripting Edition (VBScript)、 MicrosoftJScript、 Perl, 或其他腳本語(yǔ)言。 對(duì)于 Active Server Pages (ASP) 以及簡(jiǎn)單通用網(wǎng)關(guān)接口 (CGI) 腳本,IIS使用 WindowsScriptingHost 解析VBScript 和 JScript , IIS 可以使用其他腳本解釋程序。 本文介紹如何使用Python作為腳本語(yǔ)言是選擇用于 CGI 和 ASP。
在IIS管理器“網(wǎng)站”節(jié)點(diǎn)上點(diǎn)擊右鍵,選擇“屬性”“主目錄”,點(diǎn)擊“配置”按鈕,在“映射”中點(diǎn)擊“添加”,在對(duì)話框中將“可執(zhí)行文件”設(shè)置為“<python安裝目錄>/python.exe %s %s”,擴(kuò)展名為“.py”,動(dòng)作為“全部動(dòng)作”,然后點(diǎn)擊確定。
IIS現(xiàn)在就能解析Python了嗎?編寫(xiě)一個(gè)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訪問(wèn),類似http://localhost/test.py,顯示內(nèi)容為:
This is a header
See this is just like most other HTML
即可!