[英]Detecting line breaks within Python/Django textarea fields
I have a textarea field in Django from which I want to detect line breaks. 我在Django中有一个textarea字段,我想从中检测换行符。 I can see that the line breaks are stored as reloading the page with the user input shows the breaks that the user inputted, but I can't detect them in Django/Python.
我可以看到换行符的存储是因为用户输入的页面重新加载显示了用户输入的换行符,但是我无法在Django / Python中检测到它们。
When I look at the output from PostgreSQL I can see \\r characters, but these don't seem to show up within the Python environment. 当我查看PostgreSQL的输出时,可以看到\\ r字符,但是这些字符似乎未在Python环境中显示。
I'd like to do something like this: 我想做这样的事情:
text_blocks = text_area.split("\r")
But this doesn't work and I suspect is naive. 但这行不通,我怀疑是幼稚的。
How can I detect these seemingly invisible line breaks within Python/Django? 如何检测Python / Django中这些看似不可见的换行符?
Try splitlines()
, this is a built-in string method of python: 尝试
splitlines()
,这是python的内置字符串方法:
text_blocks = text_area.splitlines()
Return a list of the lines in the string, breaking at line boundaries.
返回字符串中的行列表,在行边界处中断。 Line breaks are not included in the resulting list unless keepends is given and true.
除非给出了keepends并且为true,否则换行符不包含在结果列表中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.