0

假设我们有带有 student_id 的表成绩 - 成绩 - 课程

当我在我的页面上按下 student_id 时,我将被转发到我创建的 student_id 页面。

我想要一张动态的桌子。我希望它在我添加新课程或成绩时自行更新。

表应由两列组成:等级和课程。我在 /index 上堆叠,表格显示了成绩表中的第一个元素。

这是我走了多远:

/app.py

```def load_grades():
    grades = {}
    """Loads data from input tsv files."""
    # Load students
    print("Loading grades.tsv ...")
    with open("grades.tsv", "r") as f:
        for line in f:
            student_no, name, grade = line.strip().split("\t")
            grades[student_no] = grade
    grades = dict(sorted(grades.items()))
    print(grades)
    return grades ```

/index.html

<table>
    <thead>
        <tr>
            <th>Student Number</th>
            <th>Grade</th>
        </tr>
    </thead>
    <tbody>

        {% for key, value in grades.items() %}
        <tr>
            <th> {{ key }} </th>
            <td> {{ value }} </td>
        </tr>
        {% endfor %}
    </tbody>
</table> 
4

0 回答 0