Python在新变量中将双引号转换为单引号

Bre*_*den 6 python

我试图在python中使用双引号保存变量,因为我需要将双引号JSON传递给模板,单引号不能用于我正在做的事情.所以我将python中的变量设置为:

json = {
  "auth": {
    "key": "auth-code-here"
  },
  "template_id": "id-here",
  "redirect_url": "url-here",
}
Run Code Online (Sandbox Code Playgroud)

但是直接在python中,它被保存为

{'redirect_url': 'url-here', 'template_id': 'id-here', 'auth': {'key': 'auth-code-here'}}
Run Code Online (Sandbox Code Playgroud)

有没有办法可以将它保存为双引号?或者我是否需要在django模板中处理这个以替换双引号的单引号?

谢谢!

Chr*_*per 21

您应该使用JSON模块来执行此操作.对于Python,双引号和单引号是可互换的.

Python内置了JSON功能.