0

I want have a simple model for images. there is a option to upload unlimited images. but I want don't want them to be shown under each other. for instance just show the first 5 images then some text and then again another 5. right now my code is like this:

{% for img in images %}
 <img src="{{ img.images.url }}" class="img-fluid" alt="">
{% endfor %}

I want the Structure to be like this:

  • for loop for img0 to 5,
  • then everything elese,
  • then another for loop for img6 to 10,

Thanks for the solutions and apologies for my bad English

1 Answer 1

3

You can work with the |slice template filter [Django-doc]:

{% for img in images|slice:":5" %}
    <img src="{{ img.images.url }}" class="img-fluid" alt="">
{% endfor %}

…

{% for img in images|slice:"5:10" %}
    <img src="{{ img.images.url }}" class="img-fluid" alt="">
{% endfor %}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.