91👍
✅
Use a variable.
{% extends base_template %}
and in your view, set it to “base.html” in your view, or a new “ajax.html” file which just provides the block and nothing else.
135👍
The other answers require you to pass an additional context variable. But as long as you can access the request object, there is no need:
{% extends request.is_ajax|yesno:"app/base_ajax.html,app/base.html" %}
I found this to be much more convenient.
- [Django]-Can I call a view from within another view?
- [Django]-Django : Is it impossible to static tag into block tag?
- [Django]-UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position 2: ordinal not in range(128)
29👍
{% extends override_base|default:'base.html' %}
P.s. I know this is an old question, but I found it when searching for an answer. Maybe it’ll help someone else with the same problem.
- [Django]-Django auto_now and auto_now_add
- [Django]-Django exception middleware: TypeError: object() takes no parameters
- [Django]-Django returning HTTP 301?
9👍
You can use {% extends variable %}
Pass a variable base template name in when you create the context in the view.
http://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#extends
- [Django]-Aggregate() vs annotate() in Django
- [Django]-What's the best way to store a phone number in Django models?
- [Django]-How to export virtualenv?
Source:stackexchange.com