国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

python - How to get random data every time django calls a tag
大家講道理
大家講道理 2017-05-18 10:52:56
0
3
897
The code for

views is like this
kwargs["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 it
Random 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

大家講道理
大家講道理

光陰似箭催人老,日月如移越少年。

reply all(3)
劉奇

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 %}
PHPzhong

Write a random function

洪濤

kwargs["隨機(jī)段落"] = lambda: Content.objects.order_by("?")[0].content

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template