Answer the question
In order to leave comments, you need to log in
Django template inheritance and ajax?
I just started looking towards Python + Django, so I'm familiar with them at the level of reading the documentation.
As far as I understand, Django {% extends base.html %}
should be the first line in templates. However, I would like to be able to not inherit from the base template if this is an ajax request. Apparently, the condition cannot be written here, so at the moment only this option is obvious:
In the view, we check if the request is not ajax. If ajax - render, for example, view-ajax.html
. Otherwise, view.html
in which:
{% extends base.html %}<br/>
###<br/>
{% include view-ajax.html %}
{% notajaxextends base.html %}
{% notajaxextends base.html content %}<br/>
###<br/>
{% block content %} ... {% endblock %}
Answer the question
In order to leave comments, you need to log in
You can base.html
check the flag, and if it is set, hide everything that is outside the {% block content %}
. Not very pretty, but simpler than a tag.
It is possible to render a specific block from a template. Maybe these links will help you:
http://djangosnippets.org/snippets/769/
http://djangosnippets.org/snippets/1014/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question