首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在django模板中按顺序打印cvs内容

如何在django模板中按顺序打印cvs内容
EN

Stack Overflow用户
提问于 2018-06-25 22:43:57
回答 1查看 64关注 0票数 0

这是我的django应用。它以django模板打印csv内容,但不以组织形式打印。。(请参见输出)。

views.py

代码语言:javascript
复制
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模板中这样

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2018-06-25 22:47:18

您需要将您的内容放在一个表中,看看示例here

代码语言:javascript
复制
<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>

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51026172

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档