Search code examples
djangotemplatesimgur

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


Iam using the imgur API for managing images on a website I am running. to acquire the thumbnail link you have to append a single character suffix to the end of the image id, before the file extension as described here. Is there a way to do this in the template language, or is it only possible solution as following?

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

Solution

  • You can not split and join in template(jinja). Better to go with the approach you have taken.

    Handle it in backend only.

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