--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
The tutorial is just omitting some common steps to make it simpler,
which at the same time makes it less resilient and correct.
When you setup your urlconf, you should explicitly name each URL:
urlpatterns = patterns('',
url(r'^$', 'foo.homepage', name='homepage'),
url(r'^about$', 'foo.about', name='about'),
url(r'^polls/(?P<poll_id>\d+)$', 'polls.view_poll', name='view_poll'),
)
Then, in your templates, you refer to the URLs by name, and ask Django
to sort out what the URL is:
{% for poll in polls %}
<li><a href="{% url view_poll poll.id %}">{{ poll }}</a></li>
{% endfor %}
Now, regardless of how the urlconf is tweaked, the generated HTML will
always be correct.
See the docs:
https://docs.djangoproject.com/en/1.4/topics/http/urls/#id2
https://docs.djangoproject.com/en/1.4/ref/templates/builtins/#url
Cheers
Tom