Use python to write a detailed explanation of asp

  • 2020-04-02 13:18:12
  • OfStack

One, ASP correction

Think of ASP a lot of people will say "ASP language is very painful, not object-oriented, single function, a lot of things can not achieve" and so on. The above statement is wrong, one ASp is not a language is Microsoft used to replace the CGI of a web framework, but we have been distorted in VBS is the default language of ASp, ASp and VBS draw an equal sign. Second, the Asp function is actually not a single this web provides 5 objects (request, response, server, session, appliaction) this is what Asp is born with, except that these things are all used by Asp footrel things. And ASP with the help of ASP. DLL dynamic link library, theoretically can try all scripting languages including (vbscript, jsscript, actionscript, perl, python), so ASP is a very rich flexible web framework

Why write Asp in python

Python has been in the ascendant recently, and it is playing an important role in many fields, including the web. Echosong has used django, web.py, and other python web frameworks. Due to the work required Echosong spent a large part of his time writing ASP. And VBS Asp really let a person write a kind of want to feel dead, a lot of functions with the aid of various c or other languages to write DLL stability is difficult to consider, and echosong is a full Python fan, began to contact Python in 2008 has been a hobby has not been broken, just has not been used for work.

Three, start to merge two partners together

1, asp installation: with the installation of IIS asp has become the default installation of good web framework

2. Install activepython: activepython is a special Python programming and debugging tool launched by ActiveState company.

ActivePython includes a complete Python kernel with direct calls to Python's official open source kernel, an IDE for Python programming, additional Python Windows extensions, and full access to Windows APIs. ActivePython is not open source like pure Python, but it can be downloaded for free. (note that version 2.5 can only be downloaded, and echosong was not able to download version 2.7 at the beginning. It is not clear why 500 of the results were heartless. Version 2.5 is enough.)
C:\Python25\Lib\site-packages\win32comext\axscript\client\pyscript.py;
4, complete the above two steps to start writing python Asp

Iv. Simple Demo
Connect to database file conn. Asp (connect to MSSQL database with pymssql)

 


  <%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()
%>
  

Here can be free to import python related modules!!

The data.asp file calls the conn. Asp data connection to execute the SQL statement loop that displays the value of the field to the page


<%@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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title> Headless document </title>
</head>
<body>
<%
resList = gmssql.ExecQuery("select admin_Id, admin_UserId from admin")
%>
<table>
    <tr><td> Administrator number </td><td> Management 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>
</html>


< img border = 0 id = theimg onclick = window. The open this. (SRC) SRC = "/ / files.jb51.net/file_images/article/201312/20131216091154.jpg? 2013111691334 ">

Five, the advantages of using python to write ASp

1. High code reuse: you can write the modules of your own project, write the commonly used code into python modules, and then all the code on the server can be retrieved by import

2, try python excellent features: python's powerful python library many off-the-shelf functions to use directly, rather than think of the traditional asp (VBS script) with the help of many compiled line language DLL to achieve

3, complete object oriented: VBS is a process oriented language, the characteristics of objects are very weak, many object-oriented ideas can not be used.

 

Vi. Stability and performance considerations
Did the stress test of the ability to handle transactions at the same time, various parameters are stronger than VBS, especially in connection with the database with some python excellent open source pool processing module, so that many database bottlenecks. (the relevant data screenshots were not on this computer when writing the blog)


Related articles: