Opened 10 years ago

Closed 10 years ago

#23993 closed Bug (fixed)

Default admin login.html form doesn't respect custom AuthenticationForm Media assets.

Reported by: Sveder Owned by: David A Krauth
Component: contrib.admin Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

If you replace the admin AuthenticationForm with a custom one and add form assets as described in https://docs.djangoproject.com/en/1.7/topics/forms/media/ (using the media class), it won't be reflected in the application. The root cause is that the admin/login.html template doesn't have the line {{form.media}} anywhere.

Adding that line fixes this.

Change History (9)

comment:1 by Berker Peksag, 10 years ago

How did you replace the admin authentication form? If you replace it by overriding AdminSite.login_form, you can also override the AdminSite.login_template attribute and set your custom login template path.

comment:2 by Tim Graham, 10 years ago

Triage Stage: UnreviewedAccepted

I think it's reasonable if {{ form.media }} is included in the template by default (although there is a possibility the Media class will be deprecated at some point in favor of some other hook, see #22298).

in reply to:  2 comment:3 by Sveder, 10 years ago

Replying to timgraham:

I think it's reasonable if {{ form.media }} is included in the template by default (although there is a possibility the Media class will be deprecated at some point in favor of some other hook, see #22298).

Thanks for the reply. It is such a small fix that it is worth doing even though Media might be deprecated. I'll submit a patch before the weekend is over.

in reply to:  1 comment:4 by Sveder, 10 years ago

Replying to berkerpeksag:

How did you replace the admin authentication form? If you replace it by overriding AdminSite.login_form, you can also override the AdminSite.login_template attribute and set your custom login template path.

That is indeed the workaround but it's not a good solution as you need to keep updating your new "custom" login html with whatever changes happen in Django. I think the idiomatic way to do it (for now) is using Media, and it should work as expected. Thank you for noting the workaround though, in case other people stumble over this.

comment:5 by arcturusannamalai, 10 years ago

@Sveder - I guess you should assign this ticket to yourself, since the solution is part of the problem description. Good work :-)

comment:6 by David A Krauth, 10 years ago

Owner: changed from nobody to David A Krauth
Status: newassigned

comment:7 by David A Krauth, 10 years ago

Has patch: set

comment:8 by Tino de Bruijn, 10 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by Erik Romijn <eromijn@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 88c605e3e34cebd5485d286a17ac84c7b8b0faf1:

Fixed #23993 -- Added form.media to the admin login template.

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