nfq
nfq

Reputation: 113

Django match current URL and load template

So, I am trying to load a template based on the current URL, and

For example:

{% if 'foo/bar/gallery' in request.path %}
    {% include 'web/custom/foo/bar/gallery.html' %}
{% endif %}

The foo/bar/ is dynamic, as are the directory template locations. The string 'gallery' will always be the same, and can be hardcoded if that matters. How can this be achieved?

FYI: still on django 1.3.7

Upvotes: 0

Views: 100

Answers (1)

martync
martync

Reputation: 360

I think that you should avoid the logic in the template. I suggest 2 options :

  • Prepare the name of the template in your view
  • Or, create a template tags so you can deal with the logic outside the template.

Upvotes: 1

Related Questions