views is like thiskwargs["Random Paragraph"] = Content.objects.order_by("?")[0].content
Is to randomly extract a paragraph each time
Then the index is like this
{{ 隨機(jī)段落 }}
{{ 隨機(jī)段落 }}
{{ 隨機(jī)段落 }}
My purpose is to do this every time I call itRandom paragraph 1 Random paragraph 2 Random paragraph 3
To put it simply, every time the random paragraph tag is called, go to the database to extract the data
光陰似箭催人老,日月如移越少年。
I don’t know if I understand your question.
According to my understanding, you need:
# view
# 取出多個(gè)隨機(jī)元素
# 元素個(gè)數(shù)不足什么的請(qǐng)自己注意處理
kwargs["paragraphs"] = Content.objects.order_by("?")[:3].content
{# 模版 #}
{# 在循環(huán)過(guò)程中分別渲染各個(gè)“隨機(jī)段落” #}
{% for paragraph in paragraphs %}
{{ paragraph }}
{% endfor %}