I am building a comment system on my blog and I am rendering existing comments like this:
{% for comment in comments %}
<div id="task-comments" class="pt-4">
<!-- comment-->
<div
class="bg-white rounded-lg p-3 flex flex-col justify-center items-center md:items-start shadow-lg mb-4">
<div class="flex flex-row justify-center mr-2">
<img alt="avatar" width="48" height="48"
class="rounded-full w-10 h-10 mr-4 shadow-lg mb-4"
src="https://cdn1.iconfinder.com/data/icons/technology-devices-2/100/Profile-512.png">
<h3 class="text-purple-600 font-semibold text-lg text-center md:text-left ">{{
comment.author['name']|e }}</h3>
</div>
<p style="width: 90%" class="text-gray-600 text-lg text-center md:text-left ">{{
comment.content|e }} </p>
</div>
<!-- comment end-->
<!-- comment-->
<!-- comment end-->
</div>
{% endfor %}
The problem here is that when I post a comment (using a FastAPI route), I don't know how to get the updated list of comments. I understand that Jinja may not be the best tool for this and have considered using Alpine JS x-for loop, but would love to know if there was a way to do this in Jinja natively.
Thanks!!