django - Django 关于不同的模板有不同的结果
问题描述
我是一个超级新手,所以请参考这个并阅读它。
我正在创建一个通过 DB <> API <> WEB 方法进行通信的公告板。
使用comment.html 成功导入评论。但是,无法在 boardapi_detail.html 的 {%inlude%} 处导入评论。
请参考文章底部的图片。
视图.py
class Commentapi_list(generic.TemplateView):
def get(self, request, *args, **kwargs):
data = {
'pk': self.kwargs['pk'],
}
url = 'http://127.0.0.1:8080/boardapi/' + str(data['pk']) + '/comment/'
datas = requests.get(url, params=data).json()
# print(datas)
# print(type(datas))
df = pd.DataFrame(datas)
clist = [tuple(r) for r in df.to_numpy()]
print(clist)
# print(type(clist))
return render(self.request, 'comment_form.html', {
'comment_list' : clist
})
网址.py
path('board/<int:pk>/', views.Boardapi_detail.as_view(), name="board_detail")
评论.html
{% if not comment_list %}
<p class="text-center"> There is no comment. </p>
{% endif %}
<div style="margin:20px 0;">
{% for i in comment_list %}
<table width="100%" cellpadding="0" cellspacing="0" class="tbl_replist" id="reply_list_layer">
<tbody>
<tr style="height:45px;border-top:solid 1px #dddddd;">
<td style="padding-left: 10px;border-top: 1px solid #eee;width: 114px;">{{ i.1 }}</td>
<td style="vertical-align: top;border-top: 1px solid #eee;padding: 10px 0;">{{ i.2 }}
<span style="color: #999;font-size: 11px;display: block;">{{ i.3 }}</span>
</td>
</tr>
{% if user.username == i.c_writer or user.is_staff %}
<a href="/board/{{ i.0 }}/delete/" class="btn btn-outline-success">delete</a>
{% endif %}
</tbody>
</table>
{% endfor %}
</div>
boardapi_detail.html
{% if not board_detail %}
<p class="text-center">There's nothing. </p>
{% else %}
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr style="height:45px;border-top:solid 1px #dddddd;">
<td width="20%" align="center">title</td>
<td width="80%" align="left">{{ board_detail.b_title }} </td>
</tr>
<tr style="height:45px;border-top:solid 1px #dddddd;">
<td width="20%" align="center">writer</td>
<td width="80%" align="left">{{ board_detail.b_writer }} </td>
</tr>
<tr style="height:45px;border-top:solid 1px #dddddd;">
<td width="20%" align="center">note</td>
<td width="80%" align="left">{{ board_detail.b_note }}</td>
</tr>
<tr style="height:45px;border-top:solid 1px #dddddd;">
<td width="20%" align="center">time</td>
<td width="80%" align="left">{{ board_detail.b_date }} </td>
</tr>
<tr style="height:60px;border-top:solid 1px #dddddd;" align="center">
<td width="100%" colspan="2">
<a href="/board/{{ board_detail.b_no }}/edit/" class="btn btn-outline-success">edit</a>
<button class="btn btn-outline-success my-2 my-sm-0" style="margin-right:10px;" onclick="location.href='/board/'">list</button>
</td>
</tr>
<tr style="height:45px;border-top:solid 1px #dddddd;">
<td width="20%" align="center">comment</td>
<td width="80%" align="left">({{ board.comment_set.all.count }})</td>
</tr>
</table>
{% endif %}
{% include "comment.html" %}
下面的图片是关于第一篇文章的。
↑成功导入全部3条评论。
解决方案
推荐阅读
- shiny - 通过 valueBox() 或 renderValueBox() 渲染 URL
- azure - CosmosDB 的 Spark DataFrame 编写器是否处理空行?
- amazon-web-services - 无法在 Google App 脚本中生成正确的 AWS 签名
- c++ - 矢量/算法与 iostream 不兼容
- google-cloud-platform - 使用节点 bunyan 在 GCP 中格式化日志
- ios - 键盘弹出时将原点移动到顶部时出现黑色
- java - Spring 5 Webclient 在 doAfterSuccessOrError 中抛出异常
- algorithm - 带摩擦的运动算法
- excel - Excel,如何删除excel表格中的某些范围值,如果可能的话,从表格列表中删除它们
- c# - 为什么 Pcap.net ReceivePacket 有 1000 毫秒的延迟?