0

I have an html file in my django templates that contains a forloop. I need to to have a range on the forloop that basically says the forloop will only loop through the first 10 attributes. The complication arrises when I need the range to be adujstable. I need something like a number input that keeps a varaible and then only loops through that many attributes in the forloop. I have been on it for a few days and havent made too much progress. I have worked with simple forloop ranges but havent found a way to make them adjustable. This is the forloop I have been working with.

{% for post in filter.qs %}
    {% if post.image %}
        <img class="pdf_field_img" src="{{ post.image.url }}"/>
    {% else %}
    {% endif %}

    <div class="title">Morgan Hall</div>  <div class="inspection_num">Inspection #</div>  <div 
class="inspect_num">{{ post.count_building }}</div>
{% endfor %}
Russell Hertel
  • 121
  • 3
  • 14
  • Does this answer your question? [Numeric for loop in Django templates](https://stackoverflow.com/questions/1107737/numeric-for-loop-in-django-templates) – Alireza Aug 15 '21 at 20:26
  • 1
    @Alireza I have already found that post and it helped me a little. I learned that I can user |slice:":n" to achieve what I want but I still need a way/input to change the value of n in the html file, Still no luck on my end for now. Thanks for the help so far! – Russell Hertel Aug 15 '21 at 21:24

0 Answers0