在 Django 中使用有效的 HTML 4.01 Strict

发布于 2024-08-24 17:37:28 字数 396 浏览 4 评论 0原文

我在这里找到了类似的问题,但我正在寻找更通用的解决方案。

现在,当 Django 为您生成任何类型的 HTML 时(这主要发生在生成表单时),它默认使用自闭合标签,即
而不是 < ;br>
是有效的 XHTML,我认为 HTML5 也是,但它不是有效的 HTML4。

有什么干净的方法可以覆盖这个吗?或者用 XHTML 或 HTML5 编写 django 网站更好?

I've found a similar question here, but I'm looking for more general solutions.

As it is now, when Django generates anykind of HTML for you (this mainly happens when generating forms), it uses self-closing tags by default i.e. <br /> instead of <br>. <br /> is valid XHTML and I think HTML5 also, but it's not valid HTML4.

Is there any clean way to override this? Or is it better to write django sites in XHTML or HTML5 instead?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

感情旳空白 2024-08-31 17:37:28

进行了整个系列的讨论当 1.2 的开发开始时,提出了一系列解决方案,但没有就总体前进方向达成一致。

但请参阅 Simon Willison 的 Django-HTML 项目,了解一种可能的解决方案。

There was a whole series of discussions on this when development for 1.2 kicked off, with a range of solutions proposed, but no general way forward was agreed.

But see Simon Willison's Django-HTML project for one possible solution.

会傲 2024-08-31 17:37:28

您可以完全重写 django 为您输出 HTML 的方式。 EG:对于表单,您可以:

当然,您需要新的表单来执行此操作,并且可以使用 Django 1.X。

You can rewrite entirely the way django output HTML for you. E.G : for the form, you can :

  • choose between output using table, p or li by using the property "as_xxx".
  • print the form label by label, choosing the tag wrappers.
  • use widget to define how a form piece will print to HTML.

Of course you need the new forms to do so, and there for use Django 1.X.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文