I'm pretty new to django but, I think you'll need a view that fetches all of the rows from your model. This can be done with either a listView or in with something like model.objects.all() to return the context data from your view.
Then in the template you could do:
{% for item in data %}
<td>{{ item.col1 }}</td>
<td>{{ item.col2 }}</td>
etc...
{% endfor %}
Relevant docs:
django tutorial: https://docs.djangoproject.com/en/2.2/intro/
For loop in templates: https://docs.djangoproject.com/en/2.2/ref/templates/builtins/#for
On Thu, Dec 5, 2019 at 7:48 AM Dick Arnold <darnold511@gmail.com> wrote:
I have created a table by using css examples (similar to a spread sheet). However, all the examples that I have found populate the table manually by typing td entries in the html file. How can i accomplish this with django/Python code? I have looked everywhere I can find, but no luck so far.--I had expected to find something like a FOR loop where I could simply point it to the list file and it would create the td entries automatically. My data has a fixed number of columns, but a highly variable number of rows.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1cb59233-af14-4dda-8aa2-74e663e59dd2%40googlegroups.com.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALLhV5TCz%2BDTX_HEo3kS5J2CuvMNFu2P%3D-Wutd4dE_LRA9LoTw%40mail.gmail.com.
No comments:
Post a Comment