MVC framework and MTC framework

3. WEB framework

MVC
Model View Controller
Database Template File Business Processing


MTV

Model Template View
database template file business processing


############## WEB: MVC, MTV




#coding=utf-8 from wsgiref.simple_server import make_server def handle_fun1(): f = open('test1.html',mode='rb') data = f.read() #You can add database operations here, and use the data in the database to replace the data in the template f.close() return data def handle_fun2(): return '<h1> hello func2</h1>' DICT1 = { '/text1':handle_fun1, '/text2':handle_fun2 } def Runserver(data,start_response): #data contains all the data sent by the customer #start_response encapsulates the data to be returned to the user (response headers, status, etc.) start_response('200 OK', [("Content-Type", "text/html")]) current_url = data['PATH_INFO'] print '====>',current_url func = None if current_url in DICT1: func = DICT1[current_url] if func: return func() else: return "404" #return content if __name__ == "__main__": httpobj = make_server('',8888, Runserver) print 'port HTTP on port 8888' httpobj.serve_forever()

  

test1.html
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>Our Great China</h1>
</body>
</html>

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325059305&siteId=291194637