Code

Opened 3 years ago

Closed 3 years ago

#16561 closed Bug (invalid)

incorrect url in template

Reported by: tim.proffitt@… Owned by: nobody
Component: Documentation Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

in part 3 you have us noobs write the index template:

{% if latest_poll_list %}

<ul>
{% for poll in latest_poll_list %}

<li><a href="/polls/{{ poll.id }}/">{{ poll.question }}</a></li>

{% endfor %}
</ul>

...

then we go and decouple URLconfs which includes this line:

urlpatterns = patterns('polls.views',

...

and then (and I didn't notice this until the end) when we go to mysite/polls/ and see the list of polls generated from the template and view the source the links look like so:

<a href="polls/1/"> ... </a>

the polls prefix is redundant with the changes we made to urlconfs. when you click on one of the links you will be redirected to a 404 referencing the failure to find polls/polls/n.
this issue remains even later when we use the generic templates and completely rewrite urlconfs.

Attachments (0)

Change History (1)

comment:1 Changed 3 years ago by SmileyChris

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed

Decoupling the app's URL configuration shouldn't change anything here.

Looks like you didn't follow the instructions exactly, because you should have <a href="/polls/1/">... (note the leading slash).

Here's something to look at after you've finished the tutorial, see if you can avoid hard-coding the /polls/ prefix in the template at all (Hint: url template tag or get_absolute_url+permalink decorator in the model)

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.