小编LVX*_*LVX的帖子

Django dict键,for循环中的值不起作用

我有点卡在Django问题上,我无法在for循环中访问dict的值.它在for循环之外工作,而不是在内部.

我错过了明显的吗?

蟒蛇:

err{}
err['else'] = {'class': 'Low', 'txt': 'zero'}
err['if'] = {'class': 'High', 'txt': 'one'}
data = { 'errors': err }
return render(request, 'index/error.html', data)
Run Code Online (Sandbox Code Playgroud)

HTML模板:

<p>{{ errors }}</p>
<p>{{ errors.if }}</p>
<p>{{ errors.if.class }}</p>

{% for error in errors %}
  <div class="{{ error.class }}"><p>{{ error.txt }}</p></div>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)

上面3行用于代码调试,工作得很好.for循环不会产生任何代码.

最好的问候,LVX

python django dictionary key

1
推荐指数
1
解决办法
236
查看次数

标签 统计

dictionary ×1

django ×1

key ×1

python ×1