[英]How can I get fixed output from my django database
不久前,我開始在Django Framework上編程。 我有一個帶有2個屬性的模型Questions
question_text
和id
。 當我的視圖起作用時-在瀏覽器中,我看到這樣的輸出:
[< Questions: First question >, < Questions: Second question >, < Questions:Third question >]
但我只想看看:
First question, Second question, Third question.
我該怎么解決? 在模型中帶有__str__
函數的東西還是什么?
question = Questions.objects.all()
返回一個查詢集,您顯然可以在模板中打印該查詢集。 嘗試遍歷html模板中的queryset,例如:
{% for q in questions %}
{{ q.question_text }}{% if not forloop.last %}, {% endif %}
{% endfor %}
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.