我在 views.py 中使用以下代码获取 app:
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,})
我可以打印行并获得类似以下内容的列表在 test.html
row((x1,yvalue1),(x2,yvalue2) , .... ))
但我想做的是获取所有已提取并放入数据框中的列名数据,希望使用类似下面的内容: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_sql_query.html#pandas.read_sql_query