阅读背景:

Python - Django - 添加作者

来源:互联网 

在 book_list.html 的页面下方加上 “添加作者” 的链接

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>作者列表</title>
</head>
<body>

<h1>作者列表</h1>

<table border="1">
    <thead>
    <tr>
        <th>#</th>
        <th>id</th>
        <th>名字</th>
        <th>书籍</th>
    </tr>
    </thead>
    <tbody>
        {% for author in author_list %}
            <tr>
            <td>{{ forloop.counter }}</td>
            <td>{{ author.id }}</td>
            <td>{{ author.name }}</td>
            <td>
                {% for book in author.book.all %}
                    {% if forloop.last %}
                        {{ book.title }}
                    {% else %}
                        {{ book.title }} |
                    {% endif %}
                {% endfor %}
            </td>
            </tr>
        {% endfor %}
    </tbody>
</table>

<a href="/go.html?url=/add_author/">添加书籍</a>

</body>
</html>
<!DOCT



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: