Opened 8 years ago

Closed 8 years ago

#3491 closed (fixed)

[newforms-admin] Admin templates use relative links rather than url tag

Reported by: saintsjd@… Owned by: nobody
Component: contrib.admin Version: master
Severity: Keywords:
Cc: dev@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: UI/UX:

Description

When I follow the example from the section "Custom admin views" in the djangobook chapter 18, I notice that the links in the upper right of the admin ie: "documentation", "change password", and "log out" no longer function correctly. For example, when viewing the page "admin/bookstore/report" the links in the upper right point to "admin/bookstore/report/doc" instead of "admin/doc". The Logout link points to "admin/bookstore/report/logout" instead of "admin/logout". Clicking the links results in a 404 Not Found error.

Attachments (1)

admin-patch.diff (1.3 KB) - added by mtredinnick 8 years ago.
Copy of upload to dpaste

Download all attachments as: .zip

Change History (16)

comment:1 Changed 8 years ago by Simon G. <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 8 years ago by frankie@…

  • Resolution set to invalid
  • Status changed from new to closed

This tracker is for Django itself; the book isn't tracked here. Please send an email to feedback@… instead.

comment:3 Changed 8 years ago by saintsjd@…

It seems to me that althought this bug was dicovered while using the Django Book, the bug is actually in the django admin code. The problem is that the django admin templates are using hard coded relative html hyperlinks instead of using the template function {%url%}. The admin templates need to be updated to use this template function. That would fix the problem.

comment:4 Changed 8 years ago by frankie@…

  • Resolution invalid deleted
  • Status changed from closed to reopened
  • Summary changed from Djangobook error in Chapter 18 section "custom admin views" to Admin templates use relative links rather than url tag

Sorry, my bad.

comment:5 Changed 8 years ago by Simon G. <dev@…>

Hmm.. I'm unable to recreate this bug, I've tried a custom change_form and a reworking of the example in the book (using a model I already had). However, looking at the templates, they're all relative, so I would expect there to be issues. Can you give me some more info about the views/templates you're using?

comment:6 Changed 8 years ago by Simon G. <dev@…>

  • Cc dev@… added

comment:7 Changed 8 years ago by saintsjd@…

I do not have the templates here in front of me right now, but the problem seems to come when I create admin pages more than one level down in the url path. This breaks the relative URLs.

for instance, a custom page at http://mysite.com/admin/additional_function works fine

but a custom page at http://mysite.com/admin/extra_path/additional_function does _not_ work correctly.

comment:8 Changed 8 years ago by anonymous

I tried changing the hardcoded paths like <a href="logout/">{% trans 'Log out' %}</a> to use the url template function like <a href="{% url django.contrib.auth.views.logout %}">{% trans 'Log out' %}</a> but get an error that the view cannot be found. Not sure why.

comment:9 Changed 8 years ago by saintsjd@…

  • Has patch set

I have a patch that fixes the problem. I cannot attach it tough. Trac tell me that it is spam. Please contact me if you would like the patch.

comment:10 Changed 8 years ago by Simon G. <dev@…>

  • Patch needs improvement set

Hi saintsjd, can you paste it at dpaste and link to that here (make sure you click the "hold" tag).

comment:11 Changed 8 years ago by saintsjd@…

dpaste... I should have thought of that. Here is the patch

http://dpaste.com/hold/9747/

comment:12 Changed 8 years ago by Simon G. <dev@…>

  • Triage Stage changed from Accepted to Ready for checkin

Thanks.

Changed 8 years ago by mtredinnick

Copy of upload to dpaste

comment:13 Changed 8 years ago by mtredinnick

  • Summary changed from Admin templates use relative links rather than url tag to [newforms-admin] Admin templates use relative links rather than url tag

Things in dpaste aren't "ready to checkin", because they will disappear if not accessed periodically. Please copy them over to here if they are to be preserved.

comment:14 Changed 8 years ago by Simon G. <dev@…>

Hmm sorry - there's not much else to do though if the Trac won't take it. I was going to paste it into a comment here, but I got distracted & forgot.

comment:15 Changed 8 years ago by gwilson

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [6391]) Fixed #3491 -- Fixed links in user-tools section of admin's base.html template to use the url template tag. This also removes the need for child templates to override the block just to adjust the relative path. Thanks, saintsjd@….

Note: See TracTickets for help on using tickets.
Back to Top