处理Django查询

2024-10-03 06:18:44 发布

您现在位置:Python中文网/ 问答频道 /正文

我在学Django QuerySet

这是我的观点

def CompletedFormulary(request) :
# Fonction qui donne un récapitulatif des informations du formulaire par rapport au dernier formulaire créé.

    # Reprise de tous les éléments de la table child et parent ayant l'ID le plus élevé
    identity = Identity.objects.all().order_by("-id")[0]

    identityAll = list(Identity.objects.all())
    context = {
        "identity" : identity,
        "identityAll" : identityAll,
    }

    return render(request, 'recapitulatif_identity.html',context)

我的总结_标识.html在

^{pr2}$

问题在于标识字段的显示。我想每行打印一行,如果可能的话删除[<Identity: ..... >

我不知道该怎么做。在

这就是结果

HTML page


Tags: djangoobjectsrequestdefhtmlcontextdeall
2条回答

做一个循环(见docs

{% for i in identityAll %}
<p>{{i.title}}</p>
<!  Any other property you want to add...  >
{% endfor %}

你只需要迭代一下。在

<ul>
{% for item in identityAll %}
  <li>{{ item }}</li>
{% endfor %}
</ul>

相关问题 更多 >