45👍
You could give the URL configuration which you’re using to handle the home page a name and use that:
urls.py:
from django.conf.urls.defaults import *
urlpatterns = patterns('myproject.views',
url(r'^$', 'index', name='index'),
)
Templates:
<a href="{% url index %}">...
UPDATE: Newer versions of Django require quotation marks around the name of the view:
<a href="{% url 'index' %}">...
This note in the Django Book has some tips about deploying your applications to a subdirectory:
13👍
I always use something like <a href="/">
(assuming your home is at the root, of course). I seem to recall looking this up once, and couldn’t find a Django variable for this path; at any rate, /
seemed pretty easy, anyway.
- [Django]-Nested resources in Django REST Framework
- [Django]-Get list of Cache Keys in Django
- [Django]-How to Lazy Load a model in a managers to stop circular imports?
5👍
In your admin, go to “sites” and set the domain.
Pass context_instance=RequestContext(request)
to the templates in question.
Now use {{ SITE_URL }}
in any of those templates and you’re golden.
Chapter 10 of the Django Book has more information than you’ll need regading that context processor bit.
- [Django]-How to use django-debug-toolbar for django-tastypie?
- [Django]-Django Rest framework, how to include '__all__' fields and a related field in ModelSerializer ?
- [Django]-Django – How to access the verbose_name of a Model in its Admin Module?
2👍
(r'^$', 'django.views.generic.simple.redirect_to', {'url': '/home/'}),
works fine 🙂
- [Django]-How to override and extend basic Django admin templates?
- [Django]-Django: save() vs update() to update the database?
- [Django]-Should server IP address be in ALLOWED_HOSTS django setting?