alias51
alias51

Reputation: 8608

How to test if request.url matches a specific value

I am using django, jinja2 and flask.

I have the following URL format in urls.py:

urlpatterns = patterns('',
    url(r"^gigs/(?P<pk>[0-9]+)/$", 'gig.views.event_detail', name="event_detail"),
    url(r"^gigs/(?P<pk>[0-9]+)/basket/$", 'gig.views.event_basket', name="event_basket")
)

In my template I use {% url 'event_detail' pk=event.id %} to produce the URL for the first page.

How can I write a conditional statement to test if the current URL is this first page? Something like:

{% if request.url = url 'event_music' pk=event.id %}
...
{% endif %}

Upvotes: 0

Views: 332

Answers (1)

schillingt
schillingt

Reputation: 13731

You can do it with as.

{% url 'event_detail' pk=event.id as event_music_url %}
{% if request.url == event_music_url %}
...
{% endif %}

Upvotes: 1

Related Questions