基本的 urls.py 有这样的语句,
(r'^home/$', homeview),
这里的r
到底是什么?
有什么用?
最佳答案
这是 raw strings 的前缀(转义序列被忽略)这对于理智的正则表达式很有用。
文档摘录:
When an
r'
orR'
prefix is present, backslashes are still used to quote the following character, but all backslashes are left in the string. For example, the string literalr"\n"
consists of two characters: a backslash and a lowercase'n'
因此 r'\n'
等同于 '\\n'
。
关于python - Django urls.py 中的 r 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28541257/