Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法在Django模板标记中使用Python dict_Python_Django - Fatal编程技术网

无法在Django模板标记中使用Python dict

无法在Django模板标记中使用Python dict,python,django,Python,Django,我检查了多个帖子和解决方案,但无法实现 我在视图中返回了一个Python对象。现在我想使用该dict中的数据,使用Django模板标记来呈现它 不知怎的,什么也没出现 视图: HTML 问题出在哪里?你喜欢这样吗 def render_Terminal(request, template="Terminal.html"): account_information = AccountInformation.objects.all() account_information_dict

我检查了多个帖子和解决方案,但无法实现

我在视图中返回了一个Python对象。现在我想使用该dict中的数据,使用Django模板标记来呈现它

不知怎的,什么也没出现

视图:

HTML

问题出在哪里?

你喜欢这样吗

def render_Terminal(request, template="Terminal.html"):
    account_information = AccountInformation.objects.all()
    account_information_dict = {
        'account_information': [a for a in account_information]
    }
    return render(request, template, (account_information_dict))

然后

<div id="oneTwo" class="columnsOne">
   {{ account_information.pk }}
</div>
你喜欢这样吗

def render_Terminal(request, template="Terminal.html"):
    account_information = AccountInformation.objects.all()
    account_information_dict = {
        'account_information': [a for a in account_information]
    }
    return render(request, template, (account_information_dict))

然后

<div id="oneTwo" class="columnsOne">
   {{ account_information.pk }}
</div>
AccountInformation.objects.all是一个带有all筛选器的查询集。QuerySet是可编辑的,当您第一次迭代它时,它会执行它的数据库查询。您可以使用以下命令显示列表中所有项目的id:

{帐户信息%中的项目为%0} {{item.pk} {%endfor%} AccountInformation.objects.all是一个带有all筛选器的查询集。QuerySet是可编辑的,当您第一次迭代它时,它会执行它的数据库查询。您可以使用以下命令显示列表中所有项目的id:

{帐户信息%中的项目为%0} {{item.pk} {%endfor%}
工作,谢谢你+投票表决,虽然另一个答案更广泛,这就是我接受这个答案的原因。我正在寻求帮助,但我不知道使用它的原因,所以上面有一些选项,希望你了解django如何工作以获得最佳使用,如果你有任何问题,请随时提问。工作,谢谢你+投票表决,虽然另一个答案更广泛一些,这就是我接受这个答案的原因。我正在寻求帮助,但我不知道使用它的原因是什么,所以上面有一些选项,希望您了解django如何发挥最佳作用,如果您有任何问题,请随时提问。
<div id="oneTwo" class="columnsOne">
   {{ account_information.0.pk }}
</div>
account_information = AccountInformation.objects.get(pk=`you id`)
return render(request, template, (account_information_dict))
<div id="oneTwo" class="columnsOne">
   {{ account_information.pk }}
</div>
 {% for a in account_information %}
      <div>
            {{ a.pk }}
      </div>
 {% endfor %}