天天看点

mini_frame框架添加mysql功能

# data_from_mysql = "暂时没有数据,请等待学习mysql吧,学习完mysql之后,这里就可以放入mysql查询到的数据了"
    db = pymysql.connect(host='localhost',port=3306,user='root',password='mysql',database='stock_db',charset='utf8')
    cursor = db.cursor()
    sql = """select * from info;"""
    cursor.execute(sql)
    data_from_mysql = cursor.fetchall()
    cursor.close()
    db.close()

    html_template = """
        <tr>
            <td>%d</td>
            <td>%s</td>
            <td>%s</td>
            <td>%s</td>
            <td>%s</td>
            <td>%s</td>
            <td>%s</td>
            <td>%s</td>
            <td>
                <input type="button" value="添加" id="toAdd" name="toAdd" systemidvaule="%s">
            </td>
            </tr>"""

    html = ""

    for info in data_from_mysql:
        html += html_template % (info[0], info[1], info[2], info[3], info[4], info[5], info[6], info[7], info[1])


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

    return content