【问题标题】:using array and variable from django in html在html中使用来自django的数组和变量
【发布时间】:2023-03-16 02:53:01
【问题描述】:

请告诉我如何在一个命令中使用数组和变量? 因为在 django 中我有错误:

“无法解析余数:'[show]' from 'host_value[show]'”

这是我的代码:

<form action="" method="post" >{% csrf_token %}
{% for show in showing %}
        <p><input id="autocomplete{{show}}" size="35" value="{{host_value[show]}}" name="hosts{{show}}"  title="type &quot;hostname&quot;"></p>
{% endfor %}
</form>

我的输入值有问题,我尝试从数组 host_value 中设置值,索引为“show”

我该怎么做?

【问题讨论】:

  • 你用的是数组还是字典???
  • 没有数组,比如我的host_value是:[u'zabbix2', u'Zabbix server']
  • 那么什么是“显示”,因为它看起来像一个索引?
  • 显示这个变量,显示数字从 0 到我的设置显示数字

标签: python html arrays django


【解决方案1】:

字典的Django模板语法:

{{ host_value.show }}
  • 使用点
  • 按照惯例,您希望在 {{ 之后和 }} 之前有空格

对于数组:

{{ host_value.0 }}

【讨论】:

  • 是的,谢谢,当我尝试 host_value.0 时它们正在工作,但是当 host_value.show 时,没有...
  • 我可以在数组中使用不是零而是一些变量吗?
  • 使用变量是什么意思?
猜你喜欢
  • 2017-04-03
  • 2019-12-22
  • 2013-12-01
  • 1970-01-01
  • 2017-09-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-11
相关资源
最近更新 更多