Skip to content

Commit 5f9887a

Browse files
committed
HomePage: Posts List Rendering
1 parent c4926ef commit 5f9887a

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

blog/models.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from blog import db
66

7-
87
class User(db.Model):
98
id = db.Column(db.Integer, primary_key=True)
109
created_at = db.Column(db.DateTime, default=datetime.now)

blog/routes.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
from flask import render_template
22
from blog import app
3+
from blog.models import Post
34

45

56
@app.route("/")
67
def homepage():
7-
posts = [{"title": "primo post", "body": "random body"},
8-
{"title": "secondo post", "body": "more random content"}]
9-
some_boolean_flag = False
10-
return render_template("homepage.html",
11-
posts=posts, boolean_flag=some_boolean_flag)
8+
posts = Post.query.order_by(Post.created_at.desc()).all()
9+
return render_template("homepage.html", posts=posts)
1210

1311

1412
@app.route("/about")

blog/static/blog.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ html, body {
4444
margin-bottom: 30px;
4545
}
4646

47+
.p-small-one {
48+
font-size: 0.875rem;
49+
}
50+
51+
.p-small-two {
52+
font-size: 0.800rem;
53+
}
54+
4755
@media (min-width: 768px) {
4856
.single-post-home {
4957
margin-left: 30px;

blog/templates/homepage.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@
44

55
{% block content %}
66
<div class="container content-container">
7-
87
<div class="row no-gutters">
98

109
<div class="col-md-9 order-md-2">
1110
{% for post in posts %}
1211
<div class="single-post-home">
1312
<h5>{{ post.title }}</h5>
14-
<p>{{ post.body }}</p>
13+
<p class="p-small-two text-muted">{{ post.created_at.strftime('%d.%m.%Y') }}</p>
14+
15+
{% if post.description %}
16+
<p class="p-small-one text-muted mb-0">
17+
{{ post.description }}
18+
</p>
19+
{% endif %}
1520
</div>
1621
{% endfor %}
1722
</div>
@@ -20,7 +25,6 @@ <h5>{{ post.title }}</h5>
2025
{% include 'about_me_snippet.html' %}
2126
</div>
2227

23-
</div>
24-
28+
</div>
2529
</div>
2630
{% endblock %}

0 commit comments

Comments
 (0)