[英]set command in windows not working for django SECRET_KEY | django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable
I set the SECRET_KEY with set command in the terminal, but nothing works我在终端中使用 set 命令设置了 SECRET_KEY,但没有任何效果
set SECRET_KEY='9l=jjp#g0-mbdfsntqww91s9b^a!kj44ljl4f5h!+uoft'
设置 SECRET_KEY='9l=jjp#g0-mbdfsntqww91s9b^a!kj44ljl4f5h!+uoft'
settings.py:设置.py:
from pathlib import Path
import environ
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
env = environ.Env(
DEBUG=(bool, False)
)
READ_DOT_ENV_FILE = env.bool('READ_DOT_ENV_FILE', default=False)
if READ_DOT_ENV_FILE:
environ.Env.read_env()
DEBUG = env('DEBUG')
SECRET_KEY = env('SECRET_KEY')
ALLOWED_HOSTS = []
.env: .env:
SECRET_KEY='9l=jjp#g0-mbdfsntqww91s9b^a!kj44ljl4f5h!+uoft'
DEBUG=True
So as you can read, the READ_DOT_ENV_FILE should be True to let django read the system variables from.env file, otherwise, it'll read the variables from the terminal (session) by defining them in it using the set command.如您所见,READ_DOT_ENV_FILE 应该为 True 以让 django 从 .env 文件中读取系统变量,否则,它将通过使用set命令在终端(会话)中定义变量来从终端(会话)读取变量。
In this case:在这种情况下:
set DEBUG=True设置调试=真
set SECRET_KEY='9l=jjp#g0-mbdfsntqww91s9b^a!kj44ljl4f5h!+uoft'设置 SECRET_KEY='9l=jjp#g0-mbdfsntqww91s9b^a!kj44ljl4f5h!+uoft'
Done.完毕。 I found the solution.
我找到了解决方案。 Instead of using set , you have to use:
而不是使用set ,您必须使用:
[System.Environment]::SetEnvironmentVariable('value','key')
I tried that and It works with setting the SECRET_KEY & DEBUG variables.我试过了,它适用于设置 SECRET_KEY 和 DEBUG 变量。
Closed.关闭。
I had this exact issue and I used $env:DEBUG="True".我遇到了这个确切的问题,我使用了 $env:DEBUG="True"。 $env:SECRET_KEY="paste_your_secret_key_here".
$env:SECRET_KEY="paste_your_secret_key_here"。
It's surely gonna work它肯定会起作用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.