小编Dav*_*nto的帖子

flask - 显示从python到html的数据库

我有这样的代码从数据库中检索数据,我想在html中显示它.

这是app.py

@app.route('/news')
def news():
    import pymysql
    import re

    host='localhost'
    user = 'root'
    password = ''
    db = 'skripsi'

    try:
        con = pymysql.connect(host=host,user=user,password=password,db=db, use_unicode=True, charset='utf8')
        print('+=========================+')
        print('|  CONNECTED TO DATABASE  |')
        print('+=========================+')
     except Exception as e:
        sys.exit('error',e)

     cur = con.cursor()
     cur.execute("SELECT * FROM dataset")
     data = cur.fetchall()

     for row in data:
         id_berita = row[0]
         judul = row[1]
         isi = row[2]
         print('===============================================')
         print('BERITA KE', id_berita)
         print('Judul :', judul)
         print('Isi   :', isi)
         print('===============================================')

return render_template('home.html')
Run Code Online (Sandbox Code Playgroud)

这是结果

在此输入图像描述

这是berita.html.我想在div class = …

html python flask web server

7
推荐指数
2
解决办法
3万
查看次数

标签 统计

flask ×1

html ×1

python ×1

server ×1

web ×1