Django

Code

Ticket #3491 (closed: fixed)

Opened 2 years ago

Last modified 1 year ago

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

Reported by: saintsjd@gmail.com Assigned to: nobody
Milestone: Component: django.contrib.admin
Version: SVN Keywords:
Cc: dev@simon.net.nz Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

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

admin-patch.diff (1.3 kB) - added by mtredinnick on 05/06/07 20:51:14.
Copy of upload to dpaste

Change History

02/13/07 14:36:30 changed by Simon G. <dev@simon.net.nz>

  • needs_better_patch changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • needs_docs changed.

03/07/07 04:35:54 changed by frankie@grimboy.co.uk

  • status changed from new to closed.
  • resolution set to invalid.

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

03/09/07 11:42:04 changed by saintsjd@gmail.com

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.

03/09/07 19:36:09 changed by frankie@grimboy.co.uk

  • status changed from closed to reopened.
  • resolution deleted.
  • 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.

03/10/07 04:31:09 changed by Simon G. <dev@simon.net.nz>

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?

03/10/07 04:31:40 changed by Simon G. <dev@simon.net.nz>

  • cc set to dev@simon.net.nz.

03/12/07 12:11:01 changed by saintsjd@gmail.com

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.

05/06/07 11:14:53 changed 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.

05/06/07 13:15:48 changed by saintsjd@gmail.com

  • has_patch set to 1.

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.

05/06/07 17:56:55 changed by Simon G. <dev@simon.net.nz>

  • needs_better_patch set to 1.

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

05/06/07 18:30:35 changed by saintsjd@gmail.com

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

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

05/06/07 18:38:49 changed by Simon G. <dev@simon.net.nz>

  • stage changed from Accepted to Ready for checkin.

Thanks.

05/06/07 20:51:14 changed by mtredinnick

  • attachment admin-patch.diff added.

Copy of upload to dpaste

05/06/07 20:53:10 changed 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.

05/07/07 05:58:00 changed by Simon G. <dev@simon.net.nz>

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.

09/20/07 01:59:13 changed by gwilson

  • status changed from reopened to closed.
  • resolution set to fixed.

(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@gmail.com.


Add/Change #3491 ([newforms-admin] Admin templates use relative links rather than url tag)




Change Properties
Action