Opened 10 years ago

Closed 8 years ago

#23908 closed Bug (wontfix)

settings.DEFAULT_CONTENT_TYPE = "application/xhtml+xml" breaks admin site

Reported by: Brian May Owned by: Anton Samarchyan
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: cmawebsite@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

By declaring:

DEFAULT_CONTENT_TYPE = "application/xhtml+xml"

The admin site no longer renders correctly.

I think the problem is that we haven't declared the XML namespace correctly, e.g.:

<html xmlns="http://www.w3.org/1999/xhtml">

There are also some other trivial problems, e.g. &rsaquo; no longer works (used in breadcrumbs).

Thanks

Change History (15)

comment:1 by Tim Graham, 10 years ago

Resolution: duplicate
Status: newclosed

The admin isn't designed to work as XHTML, see #19363.

comment:2 by Brian May, 10 years ago

My understanding is that XHTML is still a current standard, even with HTML5.

See http://www.w3.org/TR/html5/, note the title "A vocabulary and associated APIs for HTML and XHTML". This was published last month.

As such, the response in #19363 implying that HTML5 replaces XHTML is nonsense.

Also it possible to add something like the following in the <head> section to force use of HTML, even when XHTML is the default:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

I feel that something like Django should really keep up with the modern standards.

comment:3 by Josh Smeaton, 10 years ago

I didn't get the implication that "HTML5 replaces XHTML" from the linked ticket. Just that Django has chosen to support HTML5 rather than XHTML [N].

From your link: http://www.w3.org/TR/html5/introduction.html#html-vs-xhtml

The first such concrete syntax is the HTML syntax. This is the format suggested for most authors. ... This specification defines version 5.0 of the HTML syntax, known as "HTML 5".
The second concrete syntax is the XHTML syntax, which is an application of XML. ... This specification defines version 5.0 of the XHTML syntax, known as "XHTML 5".
The DOM, the HTML syntax, and the XHTML syntax cannot all represent the same content.

My understanding is that authors should *choose* which to support. The authors of the Admin have chosen HTML 5. You are free to choose XHTML 5 for your own templates.

HTML 5 is a modern standard. There is no requirement (demonstrated) to support multiple, competing standards though.

Is there a particular reason that you feel Django should support XHTML 5 in the admin?

Last edited 10 years ago by Josh Smeaton (previous) (diff)

comment:4 by Brian May, 10 years ago

Django Admin doesn't need to support XHTML, however it should be possible to use it with applications that do use XHTML.

As it is, it is not possible for applications to support both XHTML 5 and use Django Admin, because the DEFAULT_CONTENT_TYPE setting is global across all of Django. So you either have to use HTML or turn off Django Admin.

Not to mention XHTML being superior because parsing errors are flagged immediately rather then being ignored.

The meta setting I previously gave would allow Django admin to work as HTML even if the DEFAULT_CONTENT_TYPE setting has been changed, although it could perhaps be argued this is a bit of a kludge, as it overrides the HTTP headers.

comment:5 by Josh Smeaton, 10 years ago

In that case, would it maybe make sense to manually specify the mime/content type of all the admins HttpResponse objects? Would that avoid the problem you're seeing?

comment:6 by Brian May, 10 years ago

Yes, I believe that would be satisfactory.

I just looked at the code to try and get a vague idea of how this could be done, looks like TemplateResponse instances would need changing in django/contrib/admin/options.py - if my quick glance is sufficient.

comment:7 by Josh Smeaton, 10 years ago

Triage Stage: UnreviewedAccepted

Reopening on the basis that the admin site breaks when the following option is set: DEFAULT_CONTENT_TYPE = "application/xhtml+xml"

Since admin supports HTML 5 only - it should take measures to ensure the appropriate headers are sent when the default is not applicable.

comment:8 by Josh Smeaton, 10 years ago

Resolution: duplicate
Status: closednew

comment:9 by Collin Anderson, 10 years ago

Cc: cmawebsite@… added

I'm personally not a huge fan of having every admin view manually specify the content type. Some crazy alternatives:

  1. Recommend against DEFAULT_CONTENT_TYPE as it's a magic global setting. The admin might be one example of a bigger issue.
  2. Make the admin XHTML compatible despite what we said earlier. https://github.com/django/django/pull/3824

comment:10 by Anton Samarchyan, 8 years ago

Owner: changed from nobody to Anton Samarchyan
Status: newassigned

comment:11 by Anton Samarchyan, 8 years ago

Has patch: set
Version: 1.7master

Added PR

comment:12 by Tim Graham, 8 years ago

Patch needs improvement: set

I wrote to django-developers to try to get a consensus of whether or not we should make that change.

comment:13 by Tim Graham, 8 years ago

The consensus on the mailing list is toward deprecating the DEFAULT_CONTENT_TYPE setting. Do you have a use case that argues against that which you could add to the discussion, Brian?

comment:14 by Brian May, 8 years ago

I hadn't realised that the XHTML standards are basically dead (and doesn't appear to be supported in HTML5), in which case [deprecating settings.DEFAULT_CONTENT_TYPE] probably makes sense.

Last edited 8 years ago by Tim Graham (previous) (diff)

comment:15 by Tim Graham, 8 years ago

Resolution: wontfix
Status: assignedclosed
Summary: XHTML breaks admin sitesettings.DEFAULT_CONTENT_TYPE = "application/xhtml+xml" breaks admin site

Thanks for replying. #27829 will deprecate settings.DEFAULT_CONTENT_TYPE.

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