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_KEYis 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_stringfunction 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 ...
随机推荐
- mysql 开通远程连接
使用localhost好用,但是改成ip地址后不好用,执行sql语句做如下修改: update user set host = '%' where user = 'root'; flush privi ...
- WPF 绑定备忘单
Part I – Common Examples Basic Binding {Binding} Bind to current DataContext. {Binding Name} Bi ...
- (广搜)Catch That Cow -- poj -- 3278
链接: http://poj.org/problem?id=3278 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 6211 ...
- OpenGL中的像素包装理解
OpenGL中的像素包装理解 像素包装 位图和像素图很少会被紧密包装到内存中.在许多硬件平台上,考虑到性能的原因位图和像素图的每一行的数据会从特殊的字节对齐地址开始.绝大多数编译 器会自动把变量和缓冲 ...
- cocos2dx的addChild接口设计
addChild的几个重载函数挺容易用错的 主要是因为cocos2dx用来给游戏对象设置标签时,用的是整型而不是字符串 导致标签这个参数很容易和同样是使用整型的代表游戏对象的层级关系的参数混淆.
- Lucene--FuzzyQuery与WildCardQuery(通配符)
FuzzyQuery: 创建索引: IndexWriter writer = new IndexWriter(path, new StandardAnalyzer(), false); writer. ...
- The J-Link hardware debugging Eclipse plug-in
Quicklinks If you already know what are the features of the new plug-in and just want to know how to ...
- Java Socket实现基于TCP和UDP多线程通信
一.通过Socket实现TCP编程 1.1 TCP编程 TCP协议是面向连接,可靠的,有序的,以字节流的方式发送数据.基于TCP协议实现网络通信的类有客户端的Socket类和服务器端的ServerSo ...
- Devexpress Tab Control 文档
https://documentation.devexpress.com/WPF/8078/Controls-and-Libraries/Layout-Management/Tab-Control/P ...
- python中的基本数据类型(int,bool,str)及字符串操作
一. 基本数据类型概况 1. int 整数,主要用来进行数学运算 2. str 字符串,可以保存少量数据并进行相应的操作 3. bool 布尔值,判断真假,True,False 4. list ...