How to Detect Current Page as Homepage?

243 views
Skip to first unread message

easypie

unread,
Mar 25, 2012, 1:42:58 AM3/25/12
to django...@googlegroups.com
I'm trying to check {% if homepage %} then show <img ...> {% endif %}

I'm not sure how to go about a test to check the current page if it's my homepage. Do I need to mess around with context processors? What's the usual way of doing it? And how would the {% if ... %} look like?

Kev Dwyer

unread,
Mar 25, 2012, 3:49:33 AM3/25/12
to django...@googlegroups.com
easypie wrote:

Assuming your home is named "home" in your urls.py, you could try:

{% url home as home %}

{% if request.path == home %}<!-- do stuff -->{% endif %}

easypie

unread,
Mar 25, 2012, 1:51:42 PM3/25/12
to django...@googlegroups.com, kevin....@gmail.com
wow. thank you very much! i didn't know the extra string passed in patterns inside a tuple was used in that way too. Does this have to do with get_absolute_url too?


This is what I did:

{% url satchmo_shop_home as home %}
{% if request.path == home %}<!-- do stuff -->{% endif %}

urlspatterns += patterns('satchmo_store.shop.views',
    (r'^$', 'home.home', {}, 'satchmo_shop_home'),
    ...
)

Python_Junkie

unread,
Mar 25, 2012, 8:05:07 PM3/25/12
to django...@googlegroups.com, kevin....@gmail.com

You can retrieve the url variable that you are interested in with evaluating this variable
request.path

Use this link for more details


This is an example from the above source

def current_url_view_good(request):
    return HttpResponse("Welcome to the page at %s" % request.path)
Reply all
Reply to author
Forward
0 new messages