<a href="{{BASE_URL}}/whatever">
I'd like to be able to set this somewhere so it can be easily changed
across installations.
Thanks
--B
In myproject/settings/main.py add:
APP_URL_ROOT = 'myapp'
This is the url root for the site, (http://localhost:8000/myapp/). This
information lives in only this spot so if it changes to yourapp, I can
just change it in that one spot.
In myproject/settings/urls/main.py:
from django.conf.settings import APP_URL_ROOT
urlpatterns = patterns('',
(r'^%s/' % APP_URL_ROOT,
include('myproject.apps.myapp.urls.myapp')),
)
So I'm using the APP_URL_ROOT defined above to define the url base
here.
In my model file, for any object that I want to have a url for an
associated detail page:
def get_absolute_url(self):
from django.conf.settings import APP_URL_ROOT
return '/%s/%d' % (APP_URL_ROOT, self.id)
Then finally, in the templates, I can do:
<a href="{{ object.get_absolute_url }}"> - which would give
http://localhost:8000/myapp/1
or <a href="{{ object.get_absolute_url }}/whatever"> - which would
give http://localhost:8000/myapp/1/whatever
Hope that gives you some ideas. I'd love to hear how others have solved
this problem.
What I'd really like, though is things that can be updated via the
admin interface (or whatever) and that I can use in the templates:
{% if global.foo %}
....
--B