Dictionary not rendering in a html table in a Template

275 views
Skip to first unread message

Walter Randazzo

unread,
May 13, 2021, 7:30:09 PM5/13/21
to Django users
Hi there,

I am having some issues during a dictionary renderding on a template. Some values are showed outside the html table. I cant realize why, d u give a hand?

Thanks in advance dudes,

#This is how the dictionary is printed on the console 
 [{'socio': 'Randazzo Walter Ariel 25', 'enero': 'P', 'febrero': 'P', 'marzo': 'P', 'abril': 'P', 'mayo': 'P', 'junio': 'P', 'julio': 'P', 'agosto': 'P', 'septiembre': 'P', 'octubre': 'P', 'noviembre': 'P', 'diciembre': 'P'}, {'socio': 'Silvi Edgardo Marcelo 31', 'enero': 'P', 'febrero': 'P', 'marzo': 'P', 'abril': 'P', 'mayo': 'P', 'junio': 'P', 'julio': '-', 'agosto': '-', 'septiembre': '-', 'octubre': '-', 'noviembre': '-', 'diciembre': '-'}] 

#This is how the dictionary is rendering in the template: Image

#Template Code

Walter Randazzo

unread,
May 13, 2021, 8:24:02 PM5/13/21
to django...@googlegroups.com
Here is how the dictionary is render out in the template:

Gabriel Araya Garcia

unread,
May 13, 2021, 8:48:00 PM5/13/21
to django...@googlegroups.com
The links (image, code, and   https://tmpsee.com/v/nbkdqhnxee) they are shit. It is impossible see it. Why you don't cut and paste here in forum page ?
Gabriel Araya Garcia
GMI - Desarrollo de Sistemas Informáticos




--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAL7Dry7q1_WumJy1kKJROVD7xYFZ-2ie43LQMHJt0dLRQ9Lv0w%40mail.gmail.com.

Walter Randazzo

unread,
May 13, 2021, 10:05:11 PM5/13/21
to django...@googlegroups.com
Hi Gabriel,

I´ve just share the code via snippet to respect the identation of the code


Boris Pérez

unread,
May 14, 2021, 10:58:21 AM5/14/21
to django...@googlegroups.com
Where is the code, that u are using...
Si quieres igual hablamos en español...
Saludos...

2021-05-13 22:03 GMT-04:00, Walter Randazzo <wwran...@gmail.com>:
> Hi Gabriel,
>
> I´ve just share the code via snippet to respect the identation of the code
>
>
> El jue, 13 may 2021 a las 21:47, Gabriel Araya Garcia (<
> gabriela...@gmail.com>) escribió:
>
>> The links (image, code, and https://tmpsee.com/v/nbkdqhnxee) they are
>> shit. It is impossible see it. Why you don't cut and paste here in forum
>> page ?
>> Gabriel Araya Garcia
>> GMI - Desarrollo de Sistemas Informáticos
>>
>>
>>
>>
>> El jue, 13 may 2021 a las 20:22, Walter Randazzo (<wwran...@gmail.com>)
>> escribió:
>>
>>> Here is how the dictionary is render out in the template:
>>> https://tmpsee.com/v/nbkdqhnxee
>>>
>>> thanks
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/CAL7Dry7q1_WumJy1kKJROVD7xYFZ-2ie43LQMHJt0dLRQ9Lv0w%40mail.gmail.com
>>> <https://groups.google.com/d/msgid/django-users/CAL7Dry7q1_WumJy1kKJROVD7xYFZ-2ie43LQMHJt0dLRQ9Lv0w%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> 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...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAKVvSDDqOqnGXWZcE8wZ6V%2B-Dzy1zCudBhpR406-5sJieRaefg%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAKVvSDDqOqnGXWZcE8wZ6V%2B-Dzy1zCudBhpR406-5sJieRaefg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>
> --
> 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...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAL7Dry6v_yLMrAH8rGTmwYa8FQNgVtWmU8Rq56FF7bqCfuuPTg%40mail.gmail.com.
>

Walter Randazzo

unread,
May 14, 2021, 12:46:45 PM5/14/21
to django...@googlegroups.com
Hi Boris, Thanks for the reply.

Here is the code:

View:
Template:

Image of the rendered Template:
Regards,





Boris Pérez

unread,
May 14, 2021, 4:19:09 PM5/14/21
to django...@googlegroups.com
Hi Walter, i think the matter is that your dictionary, is not a
dictionary, is a list of dictionaries (it looks more than json
object) perhaps u wanna use jquery and ajax, into your template...
Maybe this link is usefull to u
https://stackoverflow.com/questions/51209582/django-dictionary-to-html-table-when-values-are-generators...
Greetings, Boris
>> https://groups.google.com/d/msgid/django-users/CAObPVPCx_FJrD96d0vSWMt4V4eDAQ2ZA1%3D9vKm42Q-iqhG6f_g%40mail.gmail.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...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAL7Dry56TTF8%2BN7KB0-bPgdV6bn7RZLvGje9x-6rHjFmgY1RDg%40mail.gmail.com.
>

Walter Randazzo

unread,
May 14, 2021, 7:00:40 PM5/14/21
to django...@googlegroups.com
Hi Boris,

You're right it is a list of dictionaries. I thought that the template is not able to render the data structure I used.

I will take a look on the link,thanks for  the advice.

Gracias Boris,



Walter Randazzo

unread,
May 14, 2021, 8:57:27 PM5/14/21
to django...@googlegroups.com
Hi All,

This is how I get this working..... (Thanks to Boris for the suggestion)
I have modified a the structure of the data from list of dictionaries to a dictionary.

#Now This is how the dictionary is printed in console

{'25': {'socio': 'Randazzo Walter Ariel 25', 'enero': 'P', 'febrero': 'P', 'marzo': 'P', 'abril': 'P', 'mayo': 'P', 'junio': 'P', 'julio': 'P', 'agosto': 'P', 'septiembre': 'P', 'octubre': 'P', 'noviembre': 'P', 'diciembre': 'P'}, '31': {'socio': 'Silvi Edgardo Marcelo 31', 'enero': 'P', 'febrero': 'P', 'marzo': 'P', 'abril': 'P', 'mayo': 'P', 'junio': 'P', 'julio': '-', 'agosto': '-', 'septiembre': '-', 'octubre': '-', 'noviembre': '-', 'diciembre': '-'}}

#This is how I populate the dictionary:

            dictinfopagosanual[nrosocio]={'socio':soc,
                                       'enero':EneroPago,
                                       'febrero':FebreroPago,
                                       'marzo':MarzoPago,
                                       'abril':AbrilPago,
                                       'mayo':MayoPago,
                                       'junio':JunioPago,
                                       'julio':JulioPago,
                                       'agosto':AgostoPago,
                                       'septiembre':SeptiembrePago,
                                       'octubre':OctubrePago,
                                       'noviembre':NoviembrePago,
                                       'diciembre':DiciembrePago,
        }

#Then I render in the template as follow:

        <tbody>
    {% for key,value in pagos.items %}
        <tr {% if forloop.first %}style="padding-top: 3px;" {% endif %}>
        {% for key,value in value.items %}
           <td class="text-center">{{ value }}</td>
        {% endfor %}
        </tr>
    {% endfor %}
    </tbody>



Boris Pérez

unread,
May 15, 2021, 6:19:21 PM5/15/21
to django...@googlegroups.com
Hi Walter, your template is rendering the data ok, after the changes???


2021-05-14 20:56 GMT-04:00, Walter Randazzo <wwran...@gmail.com>:
> Hi All,
>
> This is how I get this working..... (Thanks to Boris for the suggestion)
> I have modified a the structure of the data from list of dictionaries to a
> dictionary.
>
> *#Now This is how the dictionary is printed in console*
>
> {'25': {'socio': 'Randazzo Walter Ariel 25', 'enero': 'P', 'febrero': 'P',
> 'marzo': 'P', 'abril': 'P', 'mayo': 'P', 'junio': 'P', 'julio': 'P',
> 'agosto': 'P', 'septiembre': 'P', 'octubre': 'P', 'noviembre': 'P',
> 'diciembre': 'P'}, '31': {'socio': 'Silvi Edgardo Marcelo 31', 'enero':
> 'P', 'febrero': 'P', 'marzo': 'P', 'abril': 'P', 'mayo': 'P', 'junio': 'P',
> 'julio': '-', 'agosto': '-', 'septiembre': '-', 'octubre': '-',
> 'noviembre': '-', 'diciembre': '-'}}
>
> *#This is how I populate the dictionary:*
>
> dictinfopagosanual[nrosocio]={'socio':soc,
> 'enero':EneroPago,
> 'febrero':FebreroPago,
> 'marzo':MarzoPago,
> 'abril':AbrilPago,
> 'mayo':MayoPago,
> 'junio':JunioPago,
> 'julio':JulioPago,
> 'agosto':AgostoPago,
> 'septiembre':SeptiembrePago,
> 'octubre':OctubrePago,
> 'noviembre':NoviembrePago,
> 'diciembre':DiciembrePago,
> }
>
> *#Then I render in the template as follow:*
>>> https://groups.google.com/d/msgid/django-users/CAObPVPBSTCCT7M95QzC9hMARE7Fzd0gkkGtJCjQryDJChHyCKA%40mail.gmail.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...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAL7Dry6w2FfdOtT%2BG0VmnzuzXMm9eGS5dtS-MPdF4ddbPrnJ_Q%40mail.gmail.com.
>

Walter Randazzo

unread,
May 15, 2021, 6:26:08 PM5/15/21
to django...@googlegroups.com
Yes Boris. It works fine now.

Thanks,

Benny M

unread,
May 15, 2021, 6:31:31 PM5/15/21
to django...@googlegroups.com
I feel like I missed something in this exchange. The template setup looked as though it was designed to loop though a list of dictionaries. As a result, based on the code provided, it should have produced two rows of data? Was that not the case?

Benny

On May 15, 2021, at 5:25 PM, Walter Randazzo <wwran...@gmail.com> wrote:



Boris Pérez

unread,
May 15, 2021, 6:35:38 PM5/15/21
to django...@googlegroups.com
U r welcome....!!! De nada amigo...saludos
>> https://groups.google.com/d/msgid/django-users/CAObPVPDE2pg%3DgJd%3DCCkA2%2Ba-HEM44zJgOziHZVNxw8T98xYiFw%40mail.gmail.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...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAL7Dry78v1xX%3DkS-vokPsTqSsjM3xzhz7Rc%2BO%2BZbpFEtngzymA%40mail.gmail.com.
>

Walter Randazzo

unread,
May 15, 2021, 6:38:00 PM5/15/21
to django...@googlegroups.com
Hi Benny M,

Yes, two rows was rendered first but some fields were rendered out of the html table rows.

I've modified the data structure from list of dictionaries to dictionary, and now it works fine.

Thanks for your help,




Reply all
Reply to author
Forward
0 new messages