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

4

2 回答 2

2

模板中可以使用一些标签来确保添加了正确的前缀。从阅读开始:

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

于 2010-09-06T22:52:09.823 回答
1

正如 Graham 所说,{% url %}在模板中使用标签。在视图中,使用reverse()等效的函数。请参阅文档

于 2010-09-07T06:54:29.107 回答