import urllib.parse # 用于web页面编解码
import re
from pymysql import connect
url_dict = dict()
# 使用闭包传参的装饰器
def route(url): # "/index.html"
def func1(func): # index
url_dict[url] = func
def func2(*args, **kwargs):
return func(*args, **kwargs)
return func2
return func1
@route(r"/index\.html")
def index(ret):
.
.
.
return content
@route(r"/center\.html")
def center(ret):
.
.
.
return content
@route(r"/add/(\d+)\.html")
def add_stock_code(ret):
.
.
.
return "xx功能的效果"
@route(r"/del/(\d+)\.html")
def del_stock_code(ret):
.
.
.
return "xx功能的效果"
@route(r"/update/(\d+)\.html")
def update_comment(ret):
.
.
.
return "替换的内容"
@route(r"/update/(\d+)/(.*)\.html")
def save_comment(ret):
.
.
.
return "保存修改的内容"
def application(environ, start_response):
status = "200 ok"
start_response(status, [("Content-Type","text/html;charset=utf-8")])
request_name = environ["request_name"]
try:
for url, func in url_dict.items():
ret = re.match(url, request_name)
if ret:
return func(ret)
else:
return "没有对应的函数"
except:
return "route except"