tutorial error

11 views
Skip to first unread message

rihad

unread,
Nov 2, 2011, 3:24:39 AM11/2/11
to Django users
It says at the end of part 3 of the Django tutorial:

"The idea behind include() and URLconf decoupling is to make it easy
to plug-and-play URLs. Now that polls are in their own URLconf, they
can be placed under "/polls/", or under "/fun_polls/", or under "/
content/polls/", or any other path root, and the app will still work."

It's actually not that simple. Simply changing the project-wide
URLconf prefix from '^polls/' to '^fun_polls/' will not work, because
the code referencing templates still has polls in its path:
render_to_response('polls/detail.html', {'poll': p})
or in URLs:
<a href="/polls/{{ poll.id }}/">{{ poll.question }}</a>

Daniel Roseman

unread,
Nov 2, 2011, 5:29:22 AM11/2/11
to django...@googlegroups.com
Your first point is simply not true. Changing the urlconf prefix does not in any way affect how you reference the template path. You could prefix the polls URLs with 'foobar', but the template path would still be 'polls'.

The second point is made irrelevant by something that's not covered in the tutorial, but is mentioned in the actual documentation for URLs: you should never hard-code URLs, you should use the `{% url %}` tag in templates or the `reverse()` function in views - for precisely this reason.
--
DR.

rihad

unread,
Nov 2, 2011, 6:53:09 AM11/2/11
to Django users
Thanks, now I see.

p.s.: don't know where you saw two points. All I meant was that simply
changing /polls/ to /fun_polls/ will not work with the code examples
given up to that point in the tutorial, as implied by it, precisely
because URLs in the app are coupled to urlpatterns. The second part
seems to be the answer, though.

rihad

unread,
Nov 2, 2011, 7:01:07 AM11/2/11
to Django users


On Nov 2, 1:29 pm, Daniel Roseman <dan...@roseman.org.uk> wrote:
> On Wednesday, 2 November 2011 07:24:39 UTC, rihad wrote:
>
> > render_to_response('polls/detail.html', {'poll': p})


Oops, of course this has no relation to URLs, it's just a filepath :)
Reply all
Reply to author
Forward
0 new messages