Answer the question
In order to leave comments, you need to log in
How to loop through multiple blocks in django templates?
Hello!
Please help, there is such a template
Basic template
content.html
<h3>{% block post_title %}Some title{% endblock %}</h3>
<h4>{% block post_created_at %}Created by{% endblock %}</h4>
{% block short_description %}Short Desctiprtion{% endblock %}
{% block post_image %}Image{% endblock %}
<a class="bttn" href="{% block post_detail_url %}{% endblock %}">MORE</a>
{% extends 'content.html' %}
{% for p in posts %}
{% block post_title %}{{ p.title }}{% endblock %}
{% block post_created_at %}Дата создания: {{ p.created_at }}. Создал: {{ p.author }} {% endblock %}
{% block short_description %} {{ p.short_description }} {% endblock %}
{% block post_image %}{{ p.post_image }}{% endblock %}
{% block post_detail_url %} {% url 'blog:detail' p.slug %} {% endblock %}
{% endfor %}
{% block post_title %} {% for p in posts %} {{ p.title }} {%endfor %} {% endblock %}
Answer the question
In order to leave comments, you need to log in
You have a misunderstanding of inheritance in templates
Inherits from it:that file is not inserted into content.html
{% extends '
{{ p.title }}
Дата создания: {{ p.created_at }}. Создал:
.....
{% block post %}
{% for p in posts %}
{% include "p.html" %}
{% endfor%}
{% endblock %}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question