3 ms·
Sure, Django docs say this about custom context processors: https://docs.djangoproject.com/en/4.1/ref/templates/api/#writing-your-own-context-processors https:/
by pphysch 4y ago
Sure, Django docs say this about custom context processors: https://docs.djangoproject.com/en/4.1/ref/templates/api/#writing-your-own-context-processors https://docs.djangoproject.com/en/4.1/ref/templates/api/#wri...
So in my context_processors.py file, I write something like:
def base_template(request):
template = "templates/base.html" # full page
if "HX-Request" in request.headers:
template = "templates/base_ajax.html" # minimal template
return {"base_template": template}
And then my template just needs to start with `{% extends base_template %}`. Nothing needs to be done in the view (although you could technically override "base_template" there, if you need to).