我有一个numpy记录数组,数组中每个插槽有2个值。名称和偏移量,我想使用Django模板并排显示这两个值。
Python代码
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模板
--
-- 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%}
).""")
当前输出
--
-- 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"
).
期望输出
--
-- 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"
).
我需要能够使用Django模板中的for循环标记在同一行上显示2个值。如果可以使用2个单独的数组而不是numpy记录数组来完成,那么这是可以接受的。谢谢!