django sql_begin = """select ID, RuleName, KeepDays, StartUsing, CreateTime, CreateOprID, UpdateTime, UpdateOprID, DelState, ClearCount, DATE_FORMAT(ExeTime, '%H:%i:%s.%f') AS ExeTime, RuleEngName """在执行时会自动增加转义,SQL语句字符串为'select ID, RuleName, KeepDays, StartUsing, CreateTime, CreateOprID, UpdateTime, UpdateOprID, DelState, ClearCount, DATE_FORMAT(ExeTime, \'%H:%i:%s.%f\') AS ExeTime, RuleEngName ',如何解决
时间: 2024-03-12 07:48:27 浏览: 121
django model的update时auto_now不被更新的原因及解决方式
在 Python 中,可以使用原始字符串(Raw String)来避免自动转义。在原始字符串中,反斜杠不会被自动转义。
例如,你可以将 `sql_begin` 定义为原始字符串:
```python
sql_begin = r"""select ID, RuleName, KeepDays, StartUsing, CreateTime, CreateOprID, UpdateTime, UpdateOprID, DelState, ClearCount, DATE_FORMAT(ExeTime, '%H:%i:%s.%f') AS ExeTime, RuleEngName """
```
这样,字符串中的反斜杠就不会被自动转义了。
阅读全文