Python Forum
Arrange my looped template data in rows
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arrange my looped template data in rows
#1
Hello

I have Django set up to take in data from the admin. I have looped the data using template tags and template variables:

[html]
{% if Articles %}
<div class="container">
{% for col in Articles %}
<div class="item">
<h1>{{ col.title }}</h1><br><br>
<p>Columns:
{{col.columns}}</p>
</div>
{% endfor %}
</div>
{% endif %}
[/html]

each article in my database has a title and a column size. When it is looped ad displayed I have written some Jquery to target the value of the column size of each article (1 to 3) and style it:

[jquery]
<script>
$("document").ready(function () {
$(".item:contains('1')").css("width", "300");
$(".item:contains('2')").css("width", "600");
$(".item:contains('3')").css("width", "900");
})
</script>
[/jquery]

Here is my CSS:

[css]
body {
font: 1em Helvetica Neue, Helvetica, Arial, sans-serif;
text-align: center;
}

.container {
width: 900px;
border-radius: 0.5em;
padding: 10px;
display:grid;
justify-content: center;
align-content: center;


}

.item {
height: 300px;
background-color: rgba(41, 74, 111, 0.3);
border: 2px solid rgba(26, 28, 185, 0.5);
text-align: center;
float: left;


}

.item p {
margin-top: 0;
display: inline-block;
vertical-align: middle;

}

.item h1 {
font-size: 18px;
margin-top: 120px;
display: inline-block;
vertical-align: middle;
}

[/css]

This is what I want to achieve:

[Image: Screenshot-2020-02-13-at-17-41-50.png]

This is what I have:

https://i.ibb.co/2qLmCXM/Screenshot-2020...-39-43.png


Can anyone help me write a conditional statement in python that will order the blocks so there are no gaps?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how do you style data frame that has empty rows. gsaray101 0 531 Sep-08-2023, 05:20 PM
Last Post: gsaray101
  (Python) Pulling data from UA Google Analytics with more than 100k rows into csv. Stockers 0 1,230 Dec-19-2022, 11:11 PM
Last Post: Stockers
  How to properly format rows and columns in excel data from parsed .txt blocks jh67 7 1,879 Dec-12-2022, 08:22 PM
Last Post: jh67
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,634 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  Iterating Through Data Frame Rows JoeDainton123 2 2,923 Aug-09-2021, 07:01 AM
Last Post: Pedroski55
Lightbulb [Solved] df.loc: write data in certain rows ju21878436312 1 1,709 Jun-28-2021, 06:49 AM
Last Post: ju21878436312
  Pandas DataFrame combine rows by column value, where Date Rows are NULL rhat398 0 2,116 May-04-2021, 10:51 PM
Last Post: rhat398
  Indexing [::-1] to Reverse ALL 2D Array Rows, ALL 3D, 4D Array Columns & Rows Python Jeremy7 8 7,121 Mar-02-2021, 01:54 AM
Last Post: Jeremy7
  Pandas: how to split one row of data to multiple rows and columns in Python GerardMoussendo 4 6,827 Feb-22-2021, 06:51 PM
Last Post: eddywinch82
  How to filter out Column data From Multiple rows data? firaki12345 10 5,106 Feb-06-2021, 04:54 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020