python - 无法使用 django 中的模型更新帖子
问题描述
我想准备一个输出书名、出版商和作者的网页,并希望使用管理面板动态添加数据,但无法使用下面的代码来完成。请帮忙
模型.py
from django.db import models
class researchpaper(models.Model):
title = models.CharField(max_length=200)
publication = models.CharField(max_length=200)
authors = models.CharField(max_length=200)
def __str__(self) -> str:
return self.title
视图.py
def publications(request):
context = {
'researchposts': researchpaper.objects.all()
}
return render(request, 'lab/publications.html',context)
网址.py
path('publications', views.publications, name='publications'),
.html 文件
{% for paper in object_list %}
<tr>
<td>
<h5>2021</h5>
<p style="color: black;"><b>{{paper.title}}1. A minimal model for synaptic integration in simple neurons</b></p>
<p style="font-size: 14px;"><i>Physica D: Nonlinear Phenomena, 2021</i></p>
<p style="font-size: 14px;"><i>Adrian Alva, Harjinder Singh.</i></p>
</td>
<td><a href="#"
target="blank" style="color: dodgerblue;"><i class="ai ai-google-scholar-square ai-2x"
style="padding-right: 10px;"></i></a></td>
</tr>
<tr>
<td>
<hr>
</td>
</tr>
{% endfor %}
解决方案
模板中的 object_list 是否应该是研究帖子,因为这是您在上下文中提供的关键?
{% for paper in researchposts %}
...
推荐阅读
- c++ - 如何摆脱“超过时间限制”
- git - 如何在不重新克隆的情况下从 GitHub 存储库获取最近的编辑?
- python - Discord.py 禁用模块命令
- reactjs - 反应waitforelement不适用于异步调用
- image - 用户如何才能完全自由地裁剪图片
- python - Python BeautifulSoup | HTTP 错误:禁止
- events - Google Tag Manager 中的自动事件跟踪单击事件/Listerner 未在 Magento 2 网站上触发
- jquery - 无法下载jquery学习查询
- python - 为什么不 += 添加到变量的值?
- reactjs - 为什么在添加新的 React 组件时我的样式会被覆盖?