I want to realize HTML page with table which consist from date from database. And if I add element to database I want to HTML table updated too. How to realize it with django?
I want to realize HTML page with table which consist from date from database. And if I add element to database I want to HTML table updated too. How to realize it with django?
You can write something like this:
In your models.py file :
class MyModel(models.Model):foo = models.CharField(max_length=...)bar = models.CharField(max_length=...)...def __str__(self):return self.foo, self.bar
Then, in your views.py file:
def MyFunction(request):my_var = MyModel.objects.all()return render(request, 'Template.html', {"my_var": my_var})
And finally in your template.html file :
{% load staticfiles %}
{% load static %}{% block content %}{% for object in my_var_list %}<table style="width:90%"><tbody><p></p><tr><td>foo</td><td>{{ object.foo }}</td></tr><tr><td>bar</td><td>{{ object.bar }}</td></tr></tbody>
</table>{% endfor %}{% endblock content %}
Next time, read StackOverflow documentations, and what you have done before to post your question.