Admin site CSS applies success class to error messages.
The main site includes bootstrap css which uses class='danger'
to make things red, such as error messages. The django messaging framework renders error messages with class='error'
, so we include a setting to change it.
This setting applies globally, which results in the admin site also rendering error messages with class='danger'
. Unfortunately the django admin css doesn't recognize the danger class, and so doesn't apply the red background (instead defaulting to green with a checkmark, which is very confusing).
A work-around if using messages on the admin site is to include extra css classes with the extra_tags
kwarg (as in messages.error(request, message, extra_tags='error')
. But this only works when we're using the messages framework ourselves, and will not affect any messages sent by the underlying admin site code.
The longer fix is to override the default admin site templates to change css behaviour. This would involve a custom admin/base_site.html with a {% block extrastyle %}
(used here) including the necessary css.