简体   繁体   English

Django模板:自动换行和缩进块文本

[英]Django Templates: Wordwrap and indent block text

I'm a bit compulsive about having clean, readable and perfectly indented HTML. 对于具有干净,可读和完美缩进的HTML,我有些强迫。 With Django's template engine I almost have been able to achieve this with the exception of block text, or rather HTML generated by TinyMCE through the admin panel. 使用Django的模板引擎,除了块文本,或者TinyMCE通过管理面板生成的HTML之外,我几乎都能实现这一目标。 The closest I could get is using the wordwrap filter; 我能得到的最接近的是使用自动换行过滤器。 however this tag does not take any arguments to add an indentation to the new line. 但是,此标记不带任何参数来向新行添加缩进。 Is there any other way to achieve this? 还有其他方法可以做到这一点吗?

I think your only option would be to create your own filter . 我认为您唯一的选择是创建自己的过滤器

Django's django.template.defaultfilters.wordwrap uses the django.utils.text.wrap method to wrap text. Django的django.template.defaultfilters.wordwrap使用django.utils.text.wrap方法来包装文本。 You could look at that and modify the output in any way you want. 您可以查看它并以所需的任何方式修改输出。

But it looks like a lot of work for having slightly more readable HTML. 但是,要使HTML更具可读性,似乎需要做很多工作。 Sometimes good enough, is... 有时足够好,是...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM