How to check if this is the index page in Django?
Question:
How can I check of the present page is the index page in a Django template?
{% if What Goes Here??? %}
// whatever
{% endif %}
Answers:
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
...
)
{% if request.path == "/" %}
...
{% endif %}
You can just add your template code to the index page template itself.
{% if request.resolver_match.url_name == 'index' %}
// whatever
{% endif %}
How can I check of the present page is the index page in a Django template?
{% if What Goes Here??? %}
// whatever
{% endif %}
TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request',
...
)
{% if request.path == "/" %}
...
{% endif %}
You can just add your template code to the index page template itself.
{% if request.resolver_match.url_name == 'index' %}
// whatever
{% endif %}