Discussion:
if statement with url
Daxal
2010-03-10 18:51:08 UTC
Permalink
Hey,

I wanted to use a if statement with a url like ...

if you are on "/cm/add/"
......
endif
.
option 1:
I was wondering if anyone knows how to code that statement. if can
compare string variables like {% ifequal somevariable url %} where
"url" can be hard coded like "/cm/add" and somevariable would have to
store the url which i think is too complex.

option 2:
some if statement that directly compares the url like {% if {url} == "/
cm/add/" %}

any thoughts and ideas guys?

Thank you for all your replies. :)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
HARRY POTTRER
2010-03-10 21:42:40 UTC
Permalink
maybe try request.path?
Post by Daxal
Hey,
I wanted to use a if statement with a url like ...
if you are on "/cm/add/"
......
endif
.
I was wondering if anyone knows how to code that statement. if can
compare string variables like {% ifequal somevariable url %} where
"url" can be hard coded like "/cm/add" and somevariable would have to
store the url which i think is too complex.
some if statement that directly compares the url like {% if {url} == "/
cm/add/" %}
any thoughts and ideas guys?
Thank you for all your replies. :)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Nick
2010-03-10 22:38:48 UTC
Permalink
Just pop this into your template:

{% url Path.to.a.view.for.this.template as the_url %}
# you are importing a view's url structure right here and then storing
it as "the_url". Since you're not looking for anything dynamic we can
end that definition here (more here http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url)
then
{% ifequal the_url "/the/url/to/check" %} pretty self explanatory
this is the result if that is true
{% endifequal %}

It might be a good idea to check this before adding any conditional
statement:


{% url Path.to.a.view.for.this.template as the_url %}
{{ the_url }} should output the relative URL (django calls relative
paths absolute paths for some reason)
Post by HARRY POTTRER
maybe try request.path?
Post by Daxal
Hey,
I wanted to use a if statement with a url like ...
if you are on "/cm/add/"
......
endif
.
I was wondering if anyone knows how to code that statement. if can
compare string variables like {% ifequal somevariable url %} where
"url" can be hard coded like "/cm/add" and somevariable would have to
store the url which i think is too complex.
some if statement that directly compares the url like {% if {url} == "/
cm/add/" %}
any thoughts and ideas guys?
Thank you for all your replies. :)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-***@googlegroups.com.
To unsubscribe from this group, send email to django-users+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Continue reading on narkive:
Loading...