0

I pass a list into a message using the django message framework. When it is rendered in the template, I try to access the list using {{ item.0 }} for example, but nothing is coming through. If I just use {{ item }}, I can see my list.

In short, I suspect the list isn't actually a list, it is a string that looks like a list (such as "['field1','field2']").

I arrive at this conclusion because if I try to access any list item > 0, the template renders empty, which implies there is no list item beyond position 0, which is consistent with the fact that item is a string.

Messages are populated in the View as:

for item in errorRecords:
    messages.add_message(request, messages.WARNING, item)

Here, item is a list (e.g. ['field1','field2','field3']....)

Attempting to access the message list in the template:

{{ message.0 }}

works for position 0, but not for position 1 (renders blank). When access position 0, the entire list contents is shown . i.e. renders as:

['field1','field2','field3']

I want to be able to access each list's elements, so that I can populate a table with each field.

carl
  • 359
  • 2
  • 10

0 Answers0