2017-08-14 46 views
0

没有显示出来这段代码是模板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

回答

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

应该是名字那在数据库中的哪些规定

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

为外键,我希望你已经声明为

business = models.ForeignKey(modelname) 
+0

我走错误。 – 244boy

1

原因很简单:一个错字!

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

试试这个:

{{ row.bussiness_id }} 

希望它能帮助!