这是我的django应用。它以django模板打印csv内容,但不以组织形式打印。。(请参见输出)。
views.py
from django.shortcuts import render
import pandas as pd
def index(req):
df = pd.read_csv("Users\Documents\data\myproject\datanalysis\PastHires.csv")
f=df.head()
return render(req,'index.html', {'content':f})
<html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
{{content}}
</body>
</html>
OUTPUT
Years Experience Employed? Previous employers Level of Education \ 0 10 Y 4 BS 1 0 N 0 BS 2 7 N 6 BS 3 2 Y 1 MS 4 20 N 2 PhD Top-tier school Interned Hired 0 N N Y 1 Y Y Y 2 N N N 3 Y N Y 4 Y N N但是我想在我的django模板中这样
Years Experience Employed? Previous employers Level of Education \
0 10 Y 4 BS
1 0 N 0 BS
2 7 N 6 BS
3 2 Y 1 MS
4 20 N 2 PhD
Top-tier school Interned Hired
0 N N Y
1 Y Y Y
2 N N N
3 Y N Y
4 Y N N发布于 2018-06-25 22:47:18
您需要将您的内容放在一个表中,看看示例here。
<body>
<table>
<tr>
<th>Years of Experience</th>
<th>Employment Status</th>
<th>Previous Employers</th>
<th>Level of Education</th>
</tr>
{% for data in f %}
<tr>
<td>{{data.experience}}</td>
<td>{{data.employment}}</td>
<td>{{data.previous}}</td>
<td>{{data.education}}</td>
</tr>
{% endfor %}
</table>
</body>
https://stackoverflow.com/questions/51026172
复制相似问题