Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to retrieve data from a table and display it with Python and Django in an html file?

for the purposes of an introductory course in python, Django and Postgresql, I am looking for the best way to retrieve table data and display it in a structured way in an html file with Django and python as a tool and language. Thank you all for your responses

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

To display django data in html file, simply you can do this:

In views:

def login_view(request):
   user = User.objects.all() #Here I have retrieved data from user table, in django table means Model.
   return render(request, 'login.html', {'user':user}) #Here user is context

In html file:

To display data in html file. here I used curly braces to recognise context in html file

<html>
<body>
     {% for data in user %} # user is context from login view, it is used display data in html file.
          {{data}}
     {% endfor %}
</body>
</html>

Why I used curly braces in html file because it is template syntax in django

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading