Say I have an integer value that I output to a django template say x. I also have a picture that I want to print x times in a row. How would I output this picture x times in the template?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A quick but ugly hack to get this done would be using the make_list filter:
This would print the image four times (as there are four characters in the string).
A cleaner way would be to pass a list into your template using
range():Another solution (probably the cleanest one) is a custom template tag or filter, e.g.:
And in your template: