简体   繁体   English

windows 中的设置命令不适用于 django SECRET_KEY | django.core.exceptions.ImproperlyConfigured:设置 SECRET_KEY 环境变量

[英]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.

相关问题 django.core.exceptions.ImproperlyConfigured:设置SECRET_KEY环境变量 - django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable 使用 appengine “django.core.exceptions.ImproperlyConfigured:设置 SECRET_KEY 环境变量”在 Google 云上部署 Django 应用程序时出错 - Error in deploying Django app on Google cloud using appengine "django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable" 收到错误:django.core.exceptions.ImproperlyConfigured:Django 中的 SECRET_KEY 设置不能为空 - getting error : django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty in django Python django:django.core.exceptions.ImproperlyConfigured:SECRET_KEY设置不得为空 - Python django : django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty django.core.exceptions.ImproperlyConfigured:SECRET_KEY设置不能为空 - django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty Django,Celery Supervisor:秘密密钥错误:django.core.exceptions.ImproperlyConfigured:SECRET_KEY设置不得为空 - Django, Celery Supervisor: Secret Key Error: django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty 环境变量 Django:配置不当:SECRET_KEY 设置不能为空 - Environment Variables Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty Django设置SECRET_KEY - Django settings SECRET_KEY 部署Django SECRET_KEY - Deploy Django SECRET_KEY VPS 上的 Django SECRET_KEY - Django SECRET_KEY on VPS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM