views:

17

answers:

1

I feel like there is a easy answer to this but I don't know it.

I have a app that uses base template with a html link to the user's home page '../home/', but once you get 2 levels into the site, that link can't get back to the home page level.

For example, the user logs in and goes to www.yadda.com/home. When a user selects a book (#35) from the home page, I pass the book ID argument via the url and go to www.yadda.com/book/35/ rendering the book object on a template that inherits from base.html. However, when the user wants to go back to the home page, the original html link '../home/' (from base.html) puts me at www.yadda.com/book/home and not www.yadda.com/home.

An absolute path in the base to the home page would fix it, but as a django rookie, I am sure there is a more elegant solution I am unfamiliar with. Thanks in advance.

Sample Code:

urls.py

urlpatterns = patterns('booksite.views',
  (r'^schedule/(\d+)/$', 'viewBook'),
  (r'^home/$', 'home'), )

home.html

<a href="../book/{{s.id}}"> View This Book</a>

base.html

<a href="../index/">Home Page</a>
+3  A: 

In base.html, don't use ../index, use /index/.

Better yet, reverse your URLs using the {% url ... %} tag.

Dominic Rodger
thanks both work great. For some reason, I became obsessed with controlling the path and forgot that I don't need to.
rich