1.使用正则来匹配文件作为装饰器参数

@route(r"/add/(\d+)\html")

def f(ret):  s = ret.group(1)

2.防止sql注入

connect =  cs = connect.cursor()

sql="select * from info as i inner join focus as f on i.id=f.info_id where i.code=%s;"

or sql="insert into focus(info_id) select id from info where code=%s;"

or sql="delete from focue where info_id = (select id from info where code=%s);"

cs.execute(sql, (stock_code,))

cs.fetchone() / connect.commit() / cs.close() / connect.close()

3.正则替换参数

content = re.sub(r"\{%content%\}",html,content)

 4.解码

urllib.parse.unquo(' ')

 

posted on 2020-03-26 23:23  喻解  阅读(124)  评论(0编辑  收藏  举报