django 读取全部数据库数据

  • views.py中
def peoples(request):
    teacher = TeacherPeopleModel.objects.filter()
    return render(request, 'peoples.html', {'teacher': teacher})
  • model.py中
class TeacherPeopleModel(models.Model):
    # 老师的
    teacher_name = models.CharField(max_length=20)
    teacher_images = models.ImageField(upload_to='upload/')
    teacher_link = models.URLField()
    teacher_text = models.TextField(max_length=200)
  • index.html中
{% for teacher in teacher %}
<p>{{ teacher.teacher_name }}p>
<p>{{ teacher.teacher_link }}p>
{{ teacher.teacher_images }}
<p>{{ teacher.teacher_text }}p>
{% endfor %}

你可能感兴趣的:(python,web框架,django等)