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 ...
随机推荐
- C# Redis Server分布式缓存编程(二)(转)
出处;http://www.cnblogs.com/davidgu/p/3263485.html 在Redis编程中, 实体和集合类型则更加有趣和实用 namespace Zeus.Cache.Red ...
- mysql的.sql文件头部 /*!32312 IF NOT EXISTS*/;
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RE ...
- 20169221 2016-2017-2《移动平台与android开发》学习总结
每周作业连接汇总 第一周<Intellj IDEA 简易教程>学习,码云的基础使用.由于第一次写作业,网络攻防作业占据了我整个周四周五周六的时间这周java时间被挤没了,所以没有完成所有学 ...
- Android 4.3实现类似iOS在音乐播放过程中如果有来电则音乐声音渐小铃声渐大的效果
目前Android的实现是:有来电时,音乐声音直接停止,铃声直接直接使用设置的铃声音量进行铃声播放. Android 4.3实现类似iOS在音乐播放过程中如果有来电则音乐声音渐小铃声渐大的效果. 如果 ...
- ZOJ3703 Happy Programming Contest 2017-04-06 23:33 61人阅读 评论(0) 收藏
Happy Programming Contest Time Limit: 2 Seconds Memory Limit: 65536 KB In Zhejiang University P ...
- B-spline Curves 学习之B样条曲线的系数计算与B样条曲线特例(6)
B-spline Curves: Computing the Coefficients 本博客转自前人的博客的翻译版本,前几章节是原来博主的翻译内容,但是后续章节博主不在提供翻译,后续章节我在完成相关 ...
- Metasploit学习指南—基础篇
Metasploit是一款强大的渗透测试平台,其中包括了很多渗透测试利器,本文简单介绍一下Metasploit的配置和基础的使用方法,主要包括以下几个方面: Metasploit的核心 基础的配置 M ...
- EBS单实例上所有正在运行的并发请求以及请求目前的状态
--EBS单实例上所有正在运行的并发请求以及请求目前的状态---一个实例上运行的所有并发请求的总结和他们目前的状态以及等待状态 select w.seconds_in_wait "Se ...
- vue+elementui后台管理快捷代码片段
Form <el-form labelPosition="right" labelWidth="10%" size="small" : ...
- 一个例子教你理解java回调机制
网上很多例子都写的很难理解,笔者刚开始都已经弄晕菜了. 这个例子,应该是再简单,再简洁不过的了,例子目的是测试某个方法的执行时间.这里就写三个java类,一个接口,一个实现,还有一个用于测试时间的类. ...