jayt
jayt

Reputation: 768

Django - Creating an if statement based on the request path : not working

I'm trying to create a div within my view that should only be generated if both the words 'org' and 'dashboard' are in the page URL. I've looked at other similar questions on SO but they the solutions don't seem to work for me.

I have also tried putting the phrases org and dashboard within quotation marks which will actually display the div on the page; however this will be displayed on the page regardless of whether those phrases are in the page URL.

HTML:

{% if org and dashboard in request.path %}
    <div id='url-req-brn'>
      <div class='max margins'>
        <h4 id='url-req-brn-h4'>You must be logged in to view the requested page.<h4>
      </div>
    </div>
{% endif %}

Thanks

Update: Current solutions provide clarity as to the mistake I made in the HTML, however the div still doesn't display when I have a URL containing 'org' and 'dashboard'.

Do I have to define what 'request.path' means in my views.py file?

Upvotes: 1

Views: 1562

Answers (1)

Moses Koledoye
Moses Koledoye

Reputation: 78536

You'll have to quote org and dashboard as strings, and then test their containment separately:

{% if 'org' in request.path and 'dashboard' in request.path %}

The syntax follows that of plain Python.


Reference

Template complex expressions

Upvotes: 2

Related Questions