I have the following question:
I'm currently learning Flask and SQLAlchemy, in my enviroment im building a blog (a simple one). In here on my home route, I'm doing the following:
@app.route("/")
@app.route("/home")
def home():
posts = Post.query.all()
return render_template("home.html", title = "Home", posts = posts)
The posts = Post.query.all() will query all the fields on my Posts table, then on my template I'm doing the following:
{% extends "layout.html" %}
{% block content %}
{% for post in posts %}
<article class="media content-section">
<img class="rounded-circle account-img" src="{{
url_for("static", filename="profile_pics/" + post.author.image_file) }}" alt="">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="#">{{ post.author.username }}</a>
<small class="text-muted">{{ post.date_posted.strftime("%Y-%m-%d") }}</small>
</div>
<h2><a class="article-title" href="#">{{ post.title }}</a></h2>
<hr>
</div>
</article>
{% endfor %}
{% endblock %}
The problem is that in this for loop my latest post shows up as the last post , when I actually want to put it as the first one, how can I query a db through SQLAlchemy and Flask in reverse or I'm i thinking of it the wrong way?