忽略 Django 管理站点的 DEFAULT_CONTENT_TYPE?
强制 Django 管理站点应用程序中的视图返回的所有 HttpResponse
对象使用“text/html”作为其内容类型的最佳方法是什么,无论 的值是什么DEFAULT_CONTENT_TYPE
设置?我的项目将此设置为“application/xhtml+xml”,尽管管理应用程序生成的内容声称是有效的 XHTML(查看其 doctype 声明),但事实并非如此。 Ticket #5704 是一个主要问题,我发现内联表单(即自由表单)存在一些问题使用
,它不是 XHTML 中的命名实体)。 Ticket #11684 中的评论表明管理站点可能需要一段时间才能完全支持XHTML,所以我需要弄清楚如何在管理站点中使用“text/html”,同时保留默认值“application/xhtml+xml”。
What would be the best way to go about forcing all HttpResponse
objects returned by views in the Django admin site app to use "text/html" as their content type, regardless of the value of the DEFAULT_CONTENT_TYPE
setting? My project has this set to "application/xhtml+xml," and although content produced by the admin app claims to be valid XHTML (look at its doctype declaration), it is not. Ticket #5704 is a major problem, and I discovered some issues with inline forms (namely a liberal use of
, which is not a named entity in XHTML). A comment in Ticket #11684 indicates that it may be a while before the admin site will fully support XHTML, so I need to figure out how to use "text/html" for the admin site, while leaving the default as "application/xhtml+xml."
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是否是最好的方法,但我最终通过子类化
AdminSite
并覆盖admin_view
方法实现了我的目标:然后,在我的root URLconf,在调用
admin.autodiscover()
之前,我将admin.site
设置为该HTMLAdminSite
类的实例。它似乎工作正常,但如果有更好的方法,我很高兴听到。I'm not sure if this is the best way to do it or not, but I finally achieved my goal by subclassing
AdminSite
and overriding theadmin_view
method:Then, in my root URLconf, before calling
admin.autodiscover()
, I setadmin.site
to an instance of thisHTMLAdminSite
class. It seems to work okay, but if there's a better way, I'd be glad to hear it.