Opened 9 years ago

Closed 9 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 Changed 9 years ago by Berker Peksag

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 Changed 9 years ago by Tim Graham

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).

comment:3 in reply to:  2 Changed 9 years ago by Sveder

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.

comment:4 in reply to:  1 Changed 9 years ago by Sveder

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 Changed 9 years ago by arcturusannamalai

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

comment:6 Changed 9 years ago by David A Krauth

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

comment:7 Changed 9 years ago by David A Krauth

Has patch: set

comment:8 Changed 9 years ago by Tino de Bruijn

Triage Stage: AcceptedReady for checkin

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

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