Django template includes

I have a problem with django templates at the moment. I have 3 template files basically:

  • Base
  • story_list
  • story_detail

Story_list and _detail expand the base, and it works just fine. However, the list and details use code that extends the base template for the sidebar. I basically repeat a piece of code in both templates, and the programmer in me says that this is simply wrong. There must be a better way, I'm sure of it. I tried to include, however, I have in the included file:

{% block item %}
    content stuff
{% endblock %}

for about 3 blocks. The problem is that none of this is matched / displayed. If I include a file in a block section that extends the database, then it resets everything correctly, but if I do not include it in the block, I get nothing. Is this the SSI way? I played around with this, but that didn't work either. Any help is appreciated.

+3
source share
4 answers

Usually, usage is includenot the answer with Django templates. Let me answer your question on several fronts.

First let me turn to the sidebar.

  • ? Base. (.. Story_*).

  • Story_*? , Story_base, . Java. ( , jpwatts.)

, . , Story_list, Base. , {% extends "Base" %}, Story_list Base. , Story_list, , . , , , Base.

, include s. . , PHP, , include s. . . , ( Base, Story_base, Story_* ..).

+16

, , , story_base ( base) .

+6
0
{% include xxx.html %}

.

- . , .

0

Source: https://habr.com/ru/post/1708110/


All Articles