Tag block and endblock

29 views
Skip to first unread message

Nexx

unread,
Feb 25, 2019, 5:21:28 PM2/25/19
to Django users
Wht is the purpose of the tag
{% block myBlock %}
I red the document but i don't underatand.

Phako Perez

unread,
Feb 25, 2019, 5:48:20 PM2/25/19
to django...@googlegroups.com
If you see at the beginning of your template it loads/import another file which actually contains the part of code which goes in there, this block has same name like myBlock.

Hope this is helpful

Happy coding!

Sent from my iPhone
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7c8648e8-bf1a-4803-99f8-92c3a9064ae9%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Motaz Hejaze

unread,
Feb 25, 2019, 5:57:51 PM2/25/19
to django...@googlegroups.com
If you have multiple pages in a website , say , home page , about page and contact page  , now all common content that is not changing from page to like navbar , header and footer you place them in a template page  you can call it layout.html , and in this template page layout .html you define a reserved space for the content that will be changed from page to page using an empty block tag ...

Now for example lets create home page , first you extend the layout.html , then you put inside the block tag the data specific for home page only ..

You see , the purpose of this system is not to repeat the static content in navbar , header and footer in each page 

anthony....@gmail.com

unread,
Feb 26, 2019, 8:35:56 AM2/26/19
to Django users
Hi Nexx

Simply put, and as explained by Motaz, block is a django special purpose function called template tag which help to organize hierarchically your templates.

Short better than long, see the following documentation:

'hope it helps.
Reply all
Reply to author
Forward
0 new messages