0

Similar questions have been asked before on this site, but I had a doubt as to how my site anchor tags will be replaced when I try to host my website under a suburl.

E.g. My domain is www.example.com and my suburl which maps to the Django installation is www.example.com/2010/registration Now since the anchor tags in my templates (for the links) are of the form of a '/' (to reference the root) succeeded by rest of the url the links are not contained inside www.example.com. So, for example if my anchor tag is of the form

<a href='/profile'>Profile</a>

Then my anchor tag on the site becomes www.example.com/profile instead of becoming www.example.com/2010/registration/profile/

Is there any possible way to work around this thing ?

Thanks, Nitin

niting
  • 2,384
  • 3
  • 19
  • 20

2 Answers2

2

There are tags which can be used in templates to ensure correct prefix added. Start by reading:

http://docs.djangoproject.com/en/1.2/ref/templates/builtins/#url

Graham Dumpleton
  • 57,726
  • 6
  • 119
  • 134
  • What about the HttpResponseRedirect that I have used in the views ? Do i need to replace them with absolute urls manually ? – niting Sep 07 '10 at 06:08
  • @niting: No, you don't need to replace them with absolute URLs. You will be much better off naming your URLs and using `reverse()` instead of absolute URLs. – Manoj Govindan Sep 07 '10 at 07:49
1

As Graham says, use the {% url %} tag in your templates. In views, use the reverse() function, which is equivalent. See the documentation.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895