模板始终失败的变量与循环迭代器的比较

时间:2020-07-09 12:11:46

标签: django django-templates

每当来自一个模型的int变量==我的循环iteration时,我都试图打印一些东西。

我的iteration计数器正确递增,并且如果我将其更改为if data.number == '1',则测试通过。

编辑:我要提到if data.number == 1失败了,我认为这很奇怪。

我已经阅读了很多有关此的文章,并且我相信这应该可以,但是不能。

{% for iteration in range %}

{% for data in lesson_data.all %}

# this never passes
{% if data.number == iteration|add:"1" %}

谢谢。

1 个答案:

答案 0 :(得分:0)

哇,我不得不施放:

import discord
from discord.ext import commands

client = commands.Bot(command_prefix = "!")

swingsMessage = "Update me"


@client.command()
async def swings(ctx):
    await ctx.send(swingsMessage)


@client.command()
async def update(ctx,*,message):
    if str(ctx.message.author) == "buysellshort#9420":
        global swingsMessage
        swingsMessage = message