flask-wtf
Textareafield
编辑一段文字 插入数据库 再从数据库查询出来 换行符就不见了 如何将换行符一起插入数据库?
例如:
我们
你们
他们
查询出来结果就变成了:
我们 你们 他们
PHP中文网2017-04-17 17:39:17
This should be a database storage problem. Check the data type of the fields where you store these contents. Also refer to this article http://www.webtag123.com/sql/23888.html
伊谢尔伦2017-04-17 17:39:17
When outputting, include <pre>
or replace the line break in the query content with
天蓬老师2017-04-17 17:39:17
If you mean putting it in the HTML structure without line breaks, then possible problems and solutions:
Because HTML is br
newline and does not support the escape character n
. The carriage return and line feed in the textarea are not visible, and the line feed is done through n
. console.log('your query data')
Check whether there is a line break in the console. Or yourCon.indexOf("n")
to see if there is n
. If so, yourCon.replace("n","<br/>")
completes the replacement and then checks whether it is a newline. Of course, line breaks may also be r
, nr
br
换行,不支持转义字符n
。textarea里回车换行时不可见的,是通过n
换行的。console.log('你的查询数据')
看是否在控制台有换行。或者 yourCon.indexOf("n")
查看是否有n
。若有的话, yourCon.replace("n","<br/>")
完成替换, 再检查是否换行。当然换行也可能是r
、 nr
如果第一种不能解决。或者完全没有换行符的出现。那就就把数据replace("n","<br/>")
,提前把n
换成br
replace("n","<br/>")
and replace n
with br
in advance. Or just replace it with other characters before storing it in the database, and then convert it back when getting it.
🎜
🎜Click here to see my blog. I wrote a simple summary when I encountered this problem last time🎜