django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty
https://www.e-learn.cn/content/wangluowenzhang/165461
问题:
I created a new project in django and pasted some files from another project. Whenever I try to run the server, I get the following error message:
Here's my settings.py
Here's manage.py as well
Any help? Thanks!
回答1:
Just like the error says, you have no SECRET_KEY
defined. You need to add one to your settings.py.
Django will refuse to start if
SECRET_KEY
is not set.
You can read more about this setting in the docs.
The SECRET_KEY
can be just about anything...but if you want to use Django to generate one, you can do the following from the python shell:
Copy the SECRET_KEY
to your settings file.
回答2:
SECRET_KEY
variable in settings.py should be kept secret
You can place the string secret key generated with the get_random_string
function above (as said @rnevius ) in settings.py but use a function that get the variable.
This means, that for security reasons, it is better to hide the content of SECRET_KEY variable.
You can define an environment variable as follow:
In your $HOME/.bashrc
or $HOME/.zshrc
or /etc/bashrc
or /etc/bash.bashrc
according to your unix operating system and terminal manager that you use:
you can look something like this:
And in the settings.py you can add this:
The function get_env_variable tries to get the variable var_name from the environment, and if it doesn’t find it, it raises an ImproperlyConfigured error. Using it in this way, when you try to run your app and the SECRET_KEY variable is not found, you will be able to see a message indicating why our project fails.
Also you can protect the secret content variables of the project in this way.
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty的更多相关文章
- django 报错 : django.core.exceptions.ImproperlyConfigured: The STATICFILES_DIRS setting should not contain the STATIC_ROOT setting
错误原因有可能是在settings中静态文件目录设置的有问题 STATIC_ROOT=os.path.join(BASE_DIR,"static/")#错误 STATIC_ROOT ...
- pythoncharm 中解决启动server时出现 “django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured”的错误
背景介绍 最近,尝试着用pythoncharm 这个All-star IDE来搞一搞Django,于是乎,下载专业版,PJ等等一系列操作之后,终于得偿所愿.可以开工了. 错误 在园子里找了一篇初学者的 ...
- 关于Django报错django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configure
报错代码:django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but se ...
- django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call
Error info: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, ...
- django调用py报错 django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured.
完整报错信息如下 django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, bu ...
- django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)
在python的开发中,遇到了这个错误: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TA ...
- 解决:django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not 的方法
错误类型: 该错误是在在创建Django工程时出现遇到的错误 完整报错信息:(博文标题输入长度有限制) django.core.exceptions.ImproperlyConfigured: Req ...
- python基于Django框架编译报错“django.core.exceptions.ImproperlyConfigured”的解决办法?
下面是我具体遇到的问题和解决方法: 错误详细信息: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_IND ...
- django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'. Did you install mysqlclient or MySQL-python?
Error msg: Unhandled exception in thread started by <function check_errors.<locals>.wrapper ...
随机推荐
- UITableView.separatorInset
[UITableView.separatorInset] separatorInset指定每行row之间的分隔线的长度,iOS7.0后提供,官方文档如下: 示例截图如下,分隔线没有紧贴着左右边界:
- DevExpress,LayoutControl,TreeList,GridControl等
1.显示边框进行折叠 选择一个layoutControlGroupX 将其GroupBordersVisible设置成True,将TextVisiable=True 2. TreeList 2.1需要 ...
- java并发编程实战:第十四章----构建自定义的同步工具
一.状态依赖性管理 对于单线程程序,某个条件为假,那么这个条件将永远无法成真 在并发程序中,基于状态的条件可能会由于其他线程的操作而改变 可阻塞的状态依赖操作的结构 acquire lock on o ...
- 使用google chrome抓取数据:抓取全国的高中的数据
http://tomycat.github.io/blog/other/2014/05/28/use-google-chrome-capture-data.html
- [多线程] Thread
多线程 概述 单任务处理:一个任务完成后才能进行下一个任务. 多任务处理:CPU分时操作,每个任务看似同时运行. 进程 应用程序的一个运行实例,包含程序所需资源的内存区域,是操作系统进行资源分配的单元 ...
- django drf 权限permission
https://www.django-rest-framework.org/api-guide/permissions/#custom-permissions from django.shortcut ...
- SQL 判断数据库是否有相关表 字段
--判断数据库是否有相关表 if exists (select 1 from sysobjects where id = object_id(' 表名 ') and type = ' U ' ); - ...
- Plasma Cash合约解读
Plasma Cash合约解读 SmartPlasma 合约解读 1. 合约代码 2. 合约文件简单介绍 3. Plasma Cash 的基础数据结构 3.1 Plasma Cash 中的资产 3.2 ...
- (转载)Oracle的悲观锁和乐观锁
为了得到最大的性能,一般数据库都有并发机制,不过带来的问题就是数据访问的冲突.为了解决这个问题,大多数数据库用的方法就是数据的锁定. 数据的锁定分为两种方法,第一种叫做悲观锁,第二种叫做乐观锁.什么叫 ...
- djang系列5.5-- 图书管理系统实例
一.表格设计 E-R图 分析图 models.py from django.db import models # Create your models here. class Author(model ...