python - Django urls.py 中的 r 是什么?

标签 python django django-views django-urls

基本的 urls.py 有这样的语句,

(r'^home/$', homeview),

这里的r到底是什么?
有什么用?

最佳答案

这是 raw strings 的前缀(转义序列被忽略)这对于理智的正则表达式很有用。

文档摘录:

When an r' or R' prefix is present, backslashes are still used to quote the following character, but all backslashes are left in the string. For example, the string literal r"\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/

相关文章:

python - 如何将行添加到 Pandas 的现有数据框中? - Python

django - 在 VSCode 中调试 Django 在 imp.py 上失败

python - 删除应用后无法删除用户

python - 如何在我自己的 View 中使用 Django 管理列表和过滤?

python - 如何使外部数据库查询可迭代?

python - 收到 'got multiple values for keyword argument' 错误

python - 在 Python 中以制表符分隔列的形式写入文本文件

python - 使用 MacOS 的 matplotlib 的哪个后端?

python - 每个 django 模型的函数

python - Django 模型中的多对多关系