John Rogerson
John Rogerson

Reputation: 1183

Django Template--Conditional Based on The Current URL Path

I'm trying to exclude some content from the 'Blog' section of my site and would like to exclude this info on any paths that start with /blog, which would include the main /blog page and any other associated pages including blog/<blog-post> etc. I've looked at this post and tried some of the advice mentioned here but can't exactly get it to work. Here are my two blog URLs:

url(r'^$', BlogListView.as_view(), name='blog'),
url(r'^(?P<slug>[\w-]+)/$', blog_post, name='blog_post')

and what I've tried (unsuccessfully) in my django template:

{% url 'blog:blog_post' slug=slug as the_url %}
{% if request.path == the_url %}
   <div>&nbsp;</div>

{% else %}

<div class="container">
    <div class="nav-2">
      <ul class="nav nav-pills">

          {% block side_block %}

          {% get_category_list %}

            {% endblock %}

      </ul>

    </div>
    </div>
{% endif %}

Upvotes: 2

Views: 2627

Answers (1)

John Rogerson
John Rogerson

Reputation: 1183

Ok, i figured it out thanks to this post

{% if '/blog/' in request.path %}DO SOMETHING HERE{% endif %}

Upvotes: 4

Related Questions