【发布时间】:2026-02-17 06:10:02
【问题描述】:
我正在使用 Summernote 编辑器来编写博客和 sqlalchemy 来存储博客数据。所有功能工作正常。现在在主页上,我想展示我无法做到的每个博客的几行。
我在 views.py 上尝试了几个选项,但它引发了分页错误。 我还尝试了一些拆分和切片选项,但由于编辑器 html 和实际文本而没有成功。
用于获取博客文章数据的 View.py。
blog_posts = BlogPost.query.order_by(BlogPost.date.desc()).paginate(page=page,per_page=5)
index.html 用于呈现博客文章数据。 这是在for循环中
<p>{{ post.text|safe }}</p>
数据(html + 实际文本)存储在文本(数据类型)列中的 sqlite 表中,当您阅读此问题时,它只会显示实际文本
<p style="margin-top: 0.5em; margin-bottom: 0.5em; line-height: inherit; color: rgb(34, 34, 34); font-family: sans-serif; font-size: 14px; letter-spacing: normal; word-spacing: 0px;"><span style="font-size: 10px; font-family: Arial;">?</span><span style="font-family: Arial;">?</span><b><span style="font-family: Arial;">Automation</span></b><span style="font-family: Arial;"> is the technology by which a process or procedure is performed with minimal human assistance.</span><sup id="cite_ref-1" class="reference" style="line-height: 1; unicode-bidi: isolate; white-space: nowrap; font-size: 11.2px;"><a href="https://en.wikipedia.org/wiki/Automation#cite_note-1" style="text-decoration: none; color: rgb(11, 0, 128); background-image: none; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;"><span style="font-family: Arial;">[1]</span></a></sup><span style="font-family: Arial;"> Automation </span><sup id="cite_ref-Rifkin_1995_2-0" class="reference" style="line-height: 1; unicode-bidi: isolate; white-space: nowrap; font-size: 11.2px;"><a href="https://en.wikipedia.org/wiki/Automation#cite_note-Rifkin_1995-2" style="text-decoration: none; color: rgb(11, 0, 128); background-image: none; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;"><span style="font-family: Arial;">[2]</span></a></sup><span style="font-family: Arial;"> or automatic control is the use of various </span><a href="https://en.wikipedia.org/wiki/Control_system" title="Control system" style="text-decoration: none; color: rgb(11, 0, 128); background-image: none; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial;"><span style="font-family: Arial;">control systems</span></a><span style="font-family: Arial;"> for operating equipment such as machinery, processes in factories, boilers and heat treating ovens, switching on telephone networks, steering and stabilization of ships, aircraft and other applications and vehicles with minimal or reduced human intervention.</span></p><p style="margin-top: 0.5em; margin-bottom: 0.5em; line-height: inherit; color: rgb(34, 34, 34); font-family: sans-serif; font-size: 14px; letter-spacing: normal; word-spacing: 0px;"><br></p>
预期结果 - 我只想显示 3 - 5 行文本。
【问题讨论】:
-
是的 post.text|safe - 给我所有的文本,post.text|truncate(150) - 给我编辑器的所有 html 标签 + 数据(但是 html 标签很大)
-
为什么不结合安全过滤器和截断过滤器
-
合并时不工作。
标签: python flask text jinja2 flask-sqlalchemy