[英]How to change the line breaks into another character in html text areas in python?
I have a django website where user can enter recipes in a textarea. 我有一个django网站,用户可以在textarea中输入食谱。 When I want the user to enter each step of the recipe in a different line in the text area, how to I detect and change the line breaks into '\\n' when entering into the database so that when later he downloads he recipe in the form of a text file, he should see each step in different line there as well.
当我希望用户在文本区域的不同行中输入食谱的每个步骤时,在进入数据库时如何检测和更改该行会变成“ \\ n”,以便以后在他将食谱下载到数据库时形式的文本文件,他应该也可以在不同的行中看到每个步骤。
Right now, it joins all the text together when inserting into database. 现在,当插入数据库时,它将所有文本连接在一起。 Any suggestions would be highly appreciated.
任何建议将不胜感激。 Thank you in advance.
先感谢您。
The linebreaks template tag is used to render newlines (from text fields) into html breaks. 换行符模板标记用于将换行符(来自文本字段)呈现为html换行符。
{{ some_text|linebreaks }}
If some_text == Recipe\\nIngredient 1- Cilantro
the rendered output will be Recipe<br/>Ingrediant 1- Cilantro
. 如果some_text ==
Recipe\\nIngredient 1- Cilantro
则呈现的输出将为Recipe<br/>Ingrediant 1- Cilantro
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.