外键具有值,但不会显示在模板中

时间:2017-08-14 11:28:36

标签: django

此代码是模板html:

<table border="1">
    <thead>
    <tr>
        <th>1</th>
        <th>1</th>
        <th>1</th>
        <th>1</th>
        <th>1</th>
        <th>1</th>
    </tr>
    </thead>
    <tbody>
    {% for row in hosts %}
    <tr>
        <td>{{row.nid}}</td>
        <td>{{row.hostname}}</td>
        <td>{{row.ip}}</td>
        <td>{{row.port}}</td>
        <td>{{row.bussiness_ip}}</td>
        <td>{{row.bussiness.caption}}</td>
    </tr>
    {% endfor %}
    </tbody>
</table>

bussiness_ip是主机表的外键,在sqlite3中它有值:

enter image description here

row.bussiness_ip未显示,浏览器中也未显示row.bussiness.ip

enter image description here

2 个答案:

答案 0 :(得分:1)

原因很简单:错字!

在您的数据库中,该字段名为business_id,在您的模板中称为business_ip

试试这个:

 {{ row.bussiness_id }}

希望它有所帮助!

答案 1 :(得分:1)

var fd = new FormData

fd.append("key1", "value1")
fd.append("key2", "value2")

console.log(...fd)

应该是数据库中定义的名称

<td>{{row.bussiness_id}}</td>

作为外键,我希望你声明为

<td>{{ row.bussiness.id }}</td>