将单个字符后缀附加到图像 ID 的末尾,并在 django 模板中的文件扩展名之前

Appending a single character suffix to the end of the image id, and before the file extension in a django template

我正在使用 imgur API 来管理我 运行 网站上的图片。要获取缩略图 link,您必须在图像 ID 的末尾、文件扩展名 as described here 之前附加一个字符后缀。有没有办法在模板语言中做到这一点,还是只有以下可能的解决方案?

            for image in images:
            url = image.link.rsplit('.', 1)
            image.thumbs = url[0] + 'm.' + url[1]

您不能拆分和加入 template(jinja)。最好采用您采用的方法。

仅在后端处理

for image in images:
    url = image.link.rsplit('.', 1)
    image.thumbs = url[0] + 'm.' + url[1]