gpt4 book ai didi

mysql - 如何在 django 2.1.5 中显示 mysql 8 的数据?

转载 作者:行者123 更新时间:2023-11-29 15:40:13 25 4
gpt4 key购买 nike

我正在尝试在 Django 2.1 中显示来自 mysql 8 的一些数据。我创建了一个数据库db1并向其中插入一些数据并进行测试。一切都很完美。

然后我将这段代码添加到views.py中:

@login_required
def population_list(request):
names = Population.objects.all()
return render_to_response('images/image/list.html', {'names': names})

在 models.py 中我有:

class Population(models.Model):
name = models.CharField(max_length=20)
population = models.BigIntegerField()
year = models.DateField()

在 list.html 中我添加以下代码:

<div id="population-list">
<h3>Names here... </h3>

<tbody>
<tr>
{% for name in names %}
<td>{{ name.name }}</td>
{% endfor %}
</tr>
</tbody>
</div>

但是我只看到:“此处的名称...”文本,没有其他内容。我的错误是什么?为什么我看不到数据库内容?我该如何调试它?

最佳答案

我忘记在 urls.py 文件中添加路径: 路径('用户/',views.population_list,name='population_list')

关于mysql - 如何在 django 2.1.5 中显示 mysql 8 的数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57756189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com