为什么来自 table 的数据没有在 Django 中接收?
Why data from table is not recieving in django?
当我尝试从 table 检索数据时,它没有显示任何内容,而且没有给出错误消息。
这是我的模型
class staff(models.Model):
id = models.AutoField
name = models.CharField(max_length=250)
role = models.CharField(max_length=250)
salary = models.CharField(max_length=250)
address = models.CharField(max_length=250)
number = models.CharField(max_length=250)
date = models.DateField()
这是我的观点文件
def user(request):
staffs = staff.objects.all()
params = {'staff': staffs}
return render(request, "salary/user.html", params)
这是我的模板
<td> 02312 </td>
{% for staff in staffs %}
<td>{{ staff.name }} </td>
{% endfor %}
<td> ,500 </td>
试试这个
views.py
def user(request):
staffs = staff.objects.all()
return render(request, "salary/user.html", {'staff': staffs})
html
<td> 02312 </td>
{% for staffs in staff %}
<td>{{ staffs.name }} </td>
{% endfor %}
<td> ,500 </td>
当我尝试从 table 检索数据时,它没有显示任何内容,而且没有给出错误消息。
这是我的模型
class staff(models.Model):
id = models.AutoField
name = models.CharField(max_length=250)
role = models.CharField(max_length=250)
salary = models.CharField(max_length=250)
address = models.CharField(max_length=250)
number = models.CharField(max_length=250)
date = models.DateField()
这是我的观点文件
def user(request):
staffs = staff.objects.all()
params = {'staff': staffs}
return render(request, "salary/user.html", params)
这是我的模板
<td> 02312 </td>
{% for staff in staffs %}
<td>{{ staff.name }} </td>
{% endfor %}
<td> ,500 </td>
试试这个 views.py
def user(request):
staffs = staff.objects.all()
return render(request, "salary/user.html", {'staff': staffs})
html
<td> 02312 </td>
{% for staffs in staff %}
<td>{{ staffs.name }} </td>
{% endfor %}
<td> ,500 </td>