Displaying 2 values in a record array using Django template for loop

末鹿安然 提交于 2019-12-12 03:21:41

问题


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!

来源:https://stackoverflow.com/questions/33286510/displaying-2-values-in-a-record-array-using-django-template-for-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!