In my template, you need to display a lot of blocks (cards). Well, for example, such a simplistic:

<div class="cover-card col-sm-6" style="background: url(/uploads/image.jpg) no-repeat center top;background-size:cover;"> <p>Text Caption</p> </div> 

Is it possible to somehow label these blocks as tags so as not to write the entire code of the block each time?

1 answer 1

see {% include%} and own tags

https://djbook.ru/rel1.9/ref/templates/builtins.html

https://djbook.ru/rel1.9/howto/custom-template-tags.html


Use example include

 {# base.html %} ... {% for obj in obj_list %} {% include "sample.html" with object=obj %} {% endfor %} ... {# sample.html #} <div class="col-xs-12 col-sm-6 cover-card" style="backgroud-image: url({{object.image.url}});"> <p class="h4">{{ object.title }}</p> <p>{{object.description}}</p> </div> 

By the way, to reduce the html code

no-repeat center top; background-size: cover;

Take out to class