Django template question.

Asked 2 years ago, Updated 2 years ago, 54 views

Re-post the question about the long-term template.

First of all, below is my code.

<table>
    <tr>
    {% {% for entry in actress %}
        <td>{{entry.name}}</td>
    {% {% endfor %}
    </tr>

    <tr>
    {% {% for entry in actress %}
        <td><img src="static/enActress/{{entry.image_paths}}"}} }"}} class="img-circle"></td>
    {% {% endfor %}
    </tr>
</table>

My intention is to match people's names (top) and people's pictures (bottom) and put them on the table. However, when I put the entire variable in one td, the name and picture table were arranged sideways so that the browser had a scroll bar, and the div increased above the browser resolution.

I wonder how I can change the list of variables to fit the size of the container div. I think it's going to be very simple. I can't figure it out no matter how hard I try ㅠ<

django python3

2022-09-21 20:17

2 Answers

Method 1. You should use css if you want to place HTML files as you want, not as a list of text. To implement the desired functionality among csss, you can automatically change the line using Flexbox. It is a method of applying flexbox to container div and item, and creating and putting one item div for each action. You can understand what happens if you look at the link attached above.

Method 2. Use the table as it is, and change the line by making it 3 per line.

<table>
    <tr>
    {% {% for i, entry in enumerate(actress) %}
        <td>    
            {{entry.name}}</br>
            <img src="static/enActress/{{entry.image_paths}}"}} }"}} class="img-circle">
        </td>
        {% {% if i%3 ==  0 %}
            </tr><tr>
        {% {% endif %}
    {% {% endfor %}
    </tr>
</table>

You can change the line for every 3rd item like this. Instead of three, choose the number you want.


2022-09-21 20:17

The problem is that even though td continues to be created until the end of the repeat statement, I think it's because they didn't process the line down according to the appropriate number.

The solution to the problem you are facing is

If the index is greater than or equal to 5 (or an arbitrary number), you should consider the prerequisite for to print out by lowering the line.

If the word can be solved by using conditional statements
The condition that index is 5 or higher can be resolved by using forloop.counter provided by django.


2022-09-21 20:17

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.