简体   繁体   English

如何在python的html文本区域中将换行符更改为另一个字符?

[英]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.

相关问题 如何替换换行符,除非字符出现在 Python 3 中的该行中 - How to replace line breaks except if a character appears in that line in Python 3 在文本文件的每一行中,将第n个字符替换为另一个字符 - Change nth occurence of a character with another character in every line of text file 如何获取与浏览器视图匹配的换行符而不是 html 源的文本(使用 python 和 beautifulsoup) - How to get text with line breaks that match the browser view rather than the html source (using python and beautifulsoup) 如何在python中使用换行符打印文本文件内容? - How to print text file content with line breaks in python? Python - 如何向 UTF-8 编码文本添加换行符? - Python - How to add line breaks to UTF-8 encoded text? 如何在 python 中输入带有换行符的文本? - How can I user-input text with line breaks in python? 如何在python中过滤不包含换行符的大块文本? - How to filter a big chunk of text which contains no line breaks in python? 如何使用 Pillow Python 获取带有换行符的文本大小 - how to get the size of a text with line breaks with Pillow Python 如何在python中将html更改为文本? - How to change html to text in python? Jinja 在保留换行符的 HTML 中渲染文本 - Jinja render text in HTML preserving line breaks
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM