First, the rehabilitation of the ASP
Think of ASP Many people will say "ASP language is very egg pain, can not object-oriented, functional single, a lot of things can not achieve" and so on. All of the above is wrong, one of the ASP is not a language is Microsoft to replace the CGI web framework, but we have been distorted in the VBS is the ASP's default language, the ASP and VBS are equated. The second ASP function is actually not a single this web provides 5 objects (request, response, server, session, Appliaction) This is what the ASP is born with, except that these things are script-level things that are used by ASPs. and ASP with the help of Asp.dll dynamic link library, theoretically can try all scripting languages including (VBScript, JSScript, ActionScript, Perl, Python), so that ASP is a very rich flexible web framework
Two, why to write in python ASP
Python has recently been in full swing, very hot, and he occupies a pivotal position in all areas, and the web is naturally indispensable to him. Echosong has used Django, web.py, and so on Python's own web framework. Because the work needs echosong a large part of the time is in writing ASP. And the VBS ASP really let people write a kind of want to die feeling, many functions with various C or other language written DLL stability difficult to consider, and Echosong is a full of Python fans, 08 began to touch Python has been a hobby has not broken, but has not been used for work.
Three, start to merge the two small partners together
1, ASP installation: With the installation of IIS ASP becomes the default installed Web framework
2. The installation Activepython:activepython is a special Python programming and Debugging tool introduced by ActiveState company.
ActivePython contains a complete Python kernel that directly invokes the official Python open source kernel, as well as the IDE needed for Python programming, and the addition of some Python Windows extensions, as well as a full access to Windows APIs of service. ActivePython, though not as open source as pure Python, can be downloaded for free. (note version can only download 2.5, the beginning of the Echosong also do not download the 2.7 version of the results of the ruthless 500 reasons are not clear, not enough to 2.5 of the version is sufficient)
3, the command line running C:\Python25\Lib\site-packages\win32comext\axscript\client\pyscript.py;
4, complete the above two steps can be handwritten python ASP
Four, simple demo
Connect database file conn.asp (use pymssql to connect MSSQL database)
Copy Code code as follows:
<%import pymssql
Class MSSQL:
def __init__ (self,host,user,pwd,db):
Self.host = Host
Self.user = user
Self.pwd = pwd
SELF.DB = db
def __getconnect (self):
If not self.db:
Response.Write (Nameerror, "No connec Info")
Self.conn = Pymssql.connect (host=self.host,user=self.user,password=self.pwd,database=self.db,charset= "UTF8")
cur = self.conn.cursor ()
If not cur:
Response.Write (Nameerror, "Connect Err")
Else
Return cur
def getcur (self):
Return Self.__getconnect ()
def execquery (Self,sql):
cur = self.__getconnect ()
Cur.execute (SQL)
Reslist = Cur.fetchall ()
Self.conn.close ()
Return reslist
def execnonquery (Self,sql):
cur = self.__getconnect ()
Cur.execute (SQL)
Self.conn.commit ()
Self.conn.close ()
Gmssql = MSSQL (host= "* * *", user= "* * *", pwd= "* * *", db= "* * *")
Gcur = Mssql.getcur ()
%>
This is free to import Python's related modules!!!
data.asp file Call conn.asp data connection Execute SQL statement loop display field value to page
Copy Code code as follows:
<% @LANGUAGE = "python" codepage= "65001"%>
<!--#include file= "conn.asp"-->
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<title> Untitled Document </title>
<body>
<%
Reslist = Gmssql. ExecQuery ("Select admin_id, Admin_userid from admin")
%>
<table>
<tr><td> Admin Number </td><td> Admin Account </td></tr>
<%
for (Admin_id,admin_userid) in reslist:
Response.Write (U "<tr><td>" +str (admin_id) + "</td>")
Response.Write (U "<td>" +str (Admin_userid) + "<td></tr>")
%>
</table>
</body>
The advantages of using Python to write ASP
1, High code reuse: You can write your own project module, the usual commonly used code written in Python module, and then all the server can use the import to transfer
2. Try Python's best features: Python's powerful Python library has many out-of-the-box features that you can use directly, rather than traditional ASP (VBS script) DLLs with many compiled line languages
3, the complete object-oriented: VBS is a process-oriented language, objects are very weak characteristics, many object-oriented ideas can not be used.
Vi. Stability and performance considerations
Do a stress test the ability to process transactions at the same time, all aspects of the parameters stronger than the VBS, especially in the connection database with some of the Python excellent open source pool processing module, so that many database bottlenecks mitigated. (The relevant data screenshots are not on this computer when writing blog posts)