Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django include tag isn't working

Tags:

include

django

I'm trying to make my page in seperate parts - and one of them goes for the top menu, so far, however, I can't figure out how to include the top menu template in the rest of the pages. {% include "top_menu.html" %} for some reason doesn't work, do I have to update my views or smthn for it to take effect?

Thanks in advance!

like image 509
Xeen Avatar asked Sep 04 '13 16:09

Xeen


People also ask

Why include is not working in Django?

conf. urls import include is already there. In newer versions of Django, the include admin is not required anymore so django does not already have the import include part. So all you need to do to fix this in newer versions is just add the import of include there.

How to register tag in Django?

Registering the tagThe tag() method takes two arguments: The name of the template tag – a string. If this is left out, the name of the compilation function will be used. The compilation function – a Python function (not the name of the function as a string).

What is template tag in Django?

The template tags are a way of telling Django that here comes something else than plain HTML. The template tags allows us to to do some programming on the server before sending HTML to the client. template.html : <ul> {% for x in mymembers %} <li>{{ x. firstname }}</li> {% endfor %} </ul> Run Example »

What is template inheritance in Django?

Template inheritance. The most powerful – and thus the most complex – part of Django's template engine is template inheritance. Template inheritance allows you to build a base “skeleton” template that contains all the common elements of your site and defines blocks that child templates can override.


1 Answers

I had same issue and have seen quite a few other similar posts. In my case the issue was caused by my outer template having {% load staticfiles %} which was also needed by the included file.

The fix was to repeat {% load staticfiles %} inside the included file. The problem was made difficult by Django not giving an error message when it failed to load the include file, so there weren't any clues.

like image 197
Bambam Avatar answered Nov 27 '22 23:11

Bambam