Thursday, October 22, 2015

Iterating over 2 arrays or 1 record array in Django

I have a numpy record array with 2 values per slot in the array.The name and offset, I want to display both of these values side by side using a Django template.

Python code

import numpy as np  from django.template import Template, Context, loader  from django.conf import settings    dtype={      'names' : ('name','offset'),      'formats' : ('U20','U20')}    instance= np.zeros(3,dtype)      instance[0]=('xga_control_reg','008')  instance[1]=('i_cmd_REG','012')  instance[2]=('i_ee_cmd_reg','016')    t=Template(The Django Template below)  c=Context({"instance":instance['name'],"instance":instance['offset']})  print(t.render(c))

Django Template

--  --   generated with parser version 1.09  --  library ieee;  use ieee.std_logic_1164.all;    package regfile            (              {% for name  in instance%}                     Name is  {{name}}  "{{name}}"               {%endfor%}               ).""")

Current output

--  --   generated with parser version 1.09  --  library ieee;  use ieee.std_logic_1164.all;      package regfile            (                   Name is  008  "008"                    Name is  012  "012"                    Name is  016  "016"                 ).

Desired Output

--  --   generated with parser version 1.09  --  library ieee;  use ieee.std_logic_1164.all;      package regfile        (                   Name is  xga_control_reg  "008"                    Name is  i_cmd_REG  "012"                    Name is  i_ee_cmd_reg  "016"            ).

I need to be able to display 2 values on the same line using the tag for loop in a Django template. If this can be done with 2 separate arrays instead of a numpy record array, that would be acceptable. Thank you!

--
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 post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d4453921-154d-4e34-9b05-de112060048c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment