使用特殊字符在 Heroku(通过 powershell)中设置环境变量

woo*_*uck 3 django powershell heroku environment-variables

Django 1.8、Heroku、Powershell。

我正在尝试为 Heroku 中的 django 密钥设置环境变量:

(venv) PS WORKFOLDER> heroku config:set SECRET_KEY=eoik6-&dnr9elgmrt7-%3hu_&37$3hg!9c6x!^khjr3!z*z&b4
Run Code Online (Sandbox Code Playgroud)

我收到此错误消息(3 次 - 因为字符串中有 3 个&符号):

At line:1 char:77
+ heroku config:set SECRET_KEY=eoik6-&dnr9elgmrt7-%3hu_&37$3hg!9c6x!^khjr3!z*z&b4
+                                                                             ~
The ampersand (&) character is not allowed. The & operator is reserved for future use; wrap an ampersand in double
quotation marks ("&") to pass it as part of a string.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : AmpersandNotAllowed
Run Code Online (Sandbox Code Playgroud)

当我尝试建议的解决方案时(在 & 符号周围加上双引号):

(venv) PS WORKFOLDER> heroku config:set SECRET_KEY=eoik6-"&"dnr9elgmrt7-%3hu_"&"37$3hg!9c6x!^khjr3!z*z"&"b4
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

SECRET_KEY: eoik6-
'dnr9elgmrt7-%3hu_' is not recognized as an internal or external command, operable program or batch file.
'37$3hg!9c6x!^khjr3!z*z' is not recognized as an internal or external command, operable program or batch file.
'b4' is not recognized as an internal or external command, operable program or batch file.
Run Code Online (Sandbox Code Playgroud)

我也尝试用斜杠转义,在整个字符串周围加上引号等。结果相同。那么如何设置我的环境变量呢?

woo*_*uck 5

我只是尝试了一些方法,当您在整个 VALUE 周围加上单引号(和与符号周围的双引号)时,它会起作用:

heroku config:set SECRET_KEY='eoik6-"&"dnr9elgmrt7-%3hu_"&"37$3hg!9c6x!^khjr3!z*z"&"b4'
Run Code Online (Sandbox Code Playgroud)

可通过命令验证 heroku config