我在views.py中使用以下内容来获取应用
from django.db import connection
def test(request):
cursor = connection.cursor()
sql = """
SELECT x , n
from table1 limit 10
"""
cursor.execute(sql)
rows = cursor.fetchall()
# df1 = pd.read_sql_query(sql,cursor) <==> not working )
# df1.columns = cursor.keys() <==> not working )
return render(request, 'app/test.html',{ "row" : rows,})
Run Code Online (Sandbox Code Playgroud)
我能够在test.html中打印行并获得如下所示的列表
row((x1,yvalue1),(x2,yvalue2) , .... ))
Run Code Online (Sandbox Code Playgroud)
但我正在尝试做的是获取所有数据及其我获取的列名并放入数据帧,希望使用如下所示的内容: