[英]Storing bold/italic text, images in Flask backend
I am working on a Post - It/Sticky notes project where I'm using flask as the backend and React front end.我正在做一个 Post-It/Sticky notes 项目,我使用 flask 作为后端和 React 前端。 The user while typing notes can make the text as bold or italics, in the future I also want the ability to add photos/voice recordings to it.用户在输入笔记时可以将文本设置为粗体或斜体,将来我还希望能够添加照片/录音。 Basically, I want to know how do you store data that IS NOT plain text into the database,IE how do I send this bold/italic text from the front end and store it in a flask database.基本上,我想知道如何将不是纯文本的数据存储到数据库中,即如何从前端发送此粗体/斜体文本并将其存储在 flask 数据库中。
Thanks in advance!!提前致谢!!
How about storing a JSON object, like:如何存储 JSON object,例如:
storeThis = {
'type': "text",
'text': "Hey, there!",
'style': "font-size:20px;font-weight:bold;color:red;"
}
storeThis = {
'type': "img",
'src': "http://.......jpg",
'style': "height:100px;width:120px;"
}
Photos & voice recordings are best stored as blobs in the cloud or on your server, then ref'd with a url.照片和录音最好以 blob 形式存储在云端或您的服务器上,然后使用 url 进行参考。
Update更新
For more granular styling, you could store each as an HTML string.对于更精细的样式,您可以将每个样式存储为 HTML 字符串。 Example:例子:
storeThis = 'Pick up <span style="font-size:20px;font-weight:bold;color:red;">dry cleaning</span>'
Then, in the template, use the |safe
filter to display as html:然后,在模板中,使用|safe
过滤器显示为 html:
{{ storeThis|safe }} {{ storeThis|安全 }}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.