【发布时间】:2014-03-10 05:04:52
【问题描述】:
我是 Django 新手,所以我只是构建了一些简单的应用程序来增加我的知识。我正在尝试显示串联列表,但是当我显示列表时,它会显示模型名称,如下所示:
[<FamousQuote: Be yourself; everyone else is already taken>][<InfamousQuote: . I dunno. Either way. >]
这是我的views.py文件:
def index(request):
famous_quote = FamousQuote.objects.all().order_by('?')[:1]
infamous_quote = InfamousQuote.objects.all().order_by('?')[:1]
compiled = [famous_quote, infamous_quote]
return render(request, 'funnyquotes/index.html', {'compiled': compiled})
还有我的 index.html 文件:
{% if compiled %}
{{ compiled|join:"" }}
{% else %}
<p>No quotes for you.</p>
{% endif %}
我做错了什么,还是有更好的方法可以做到这一点?
【问题讨论】:
-
你想要的结果是什么?
-
能否请您发布您的
models.py文件?