Inte L Inte L - 4 years ago 152
Python Question

My Django if statement do not work correctly

I have created a admin panel on the frontend and would like to show different layouts if they are on the index.html or if they are on pages after /admin e.g:

/admin/dashboard
/admin/posts
/admin/media


My if statement:

{% if request.path == "/admin" %}


It doesn't work for some reason and I can't figure out why. This is an example of the whole if:

<div class="row">

{% if request.path == "/admin" %}
<div class="col-md-full">
{% else %}
<div class="col-md-7 left">
{% block main %}{% endblock %}
</div>
{% endif %}

{% if request.path == "/admin" %}
{% trans "Empty" %}
{% else %}
<div class="col-md-3 right">
<div class="panel panel-default">
<div class="panel-body">
{% block right_panel %}
{% endblock %}
</div>
</div>
</div>
{% endif %}

</div>

Answer Source

what about?

{% if '/admin/' in request.path %}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download