当前位置:Gxlcms > 数据库问题 > django -----原生SQL语句查询与前端数据传递?

django -----原生SQL语句查询与前端数据传递?

时间:2021-07-01 10:21:17 帮助过:4人阅读

import MySQL

 

def request_data(request):
    if request.method == "GET":
        conn = MySQLdb.Connect(
                host =my_ip,
                port = 3306,
                user = my_user,
                passwd = my_passwd,
                db = my_db,
                charset = utf8
        )
        cursor = conn.cursor()
        cursor.execute("select * from my_table limit 1")
        values=cursor.fetchall()

        print(values)

        cursor.close()
        conn.close()
        return render(request,"data.html",{results:values})

 

 

 

def GetList(sql):
    db = MySQLdb.connect(user=root, db=wupeiqidb, passwd=1234, host=localhost)
    cursor = db.cursor()
    cursor.execute(sql)
    data = cursor.fetchall()
    db.close()
    return data

 

django -----原生SQL语句查询与前端数据传递?

标签:class   sele   charset   16px   语句   ble   hal   host   values   

人气教程排行