Displaying a Table in Django from Database

前端 未结 3 1359
无人及你
无人及你 2020-12-22 19:26

How do you display the information from a database table in a table format on a webpage? Is there a simple way to do this in django or does it require a more complicated app

3条回答
  •  天涯浪人
    2020-12-22 19:51

    If you want to table do following steps:-

    views.py:

    def view_info(request):
        objs=Model_name.objects.all()
        ............
        return render(request,'template_name',{'objs':obj})
    

    .html page

     {% for item in objs %}
         
             {{ item.field1 }}
             {{ item.field2 }}
             {{ item.field3 }}
             {{ item.field4 }}
        
           {% endfor %}
    

提交回复
热议问题