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# FTPClientHelper共公类 实现文件上传,目录操作,下载等动作
文档说明 本文档使用Socket通信方式来实现ftp文件的上传下载等命令的执行 1.基本介绍 由于最近的项目是客户端的程序,需要将客户端的图片文件[切图]-[打包]-[ftp上传],现在就差最后一步了 ...
- handsontable-developer guide-cell type
单元格类型:这里有很多没见过的用法,得好好总结一下 //预定义的类型Text Numeric Checkbox Date Select Dropdown Autocomplete Password H ...
- Web 应用简单测试方案
测试:一定要分阶段测试,先确定入队列成功,再测试队列的执行是否成功. 功能点: 1. 翻页2. 加精3. 置顶4. 帖子浏览量(PV)5. 发帖6. 回复7. 评论 8. crontab 脚本 @20 ...
- Android-bindService本地服务-音乐播放-上
播放音乐的行为写在服务里,Activity去调用Service里面到方法,进行音乐播放,当Activity结束后,音乐播放器停止播放 界面: MainActivity: package liudeli ...
- 生成Webservice的两种方式(Axis2,CXf2.x)
一天之中,用了各种方式生成webservice,就是为了node.js能和程序顺利通信.最终还是用axis2成功了.工作基本完成了,现在可以总结一下. 关于生成方式,推荐使用eclipse,比较方便, ...
- 配置sql server 允许远程连接
如果要想远程连接数据库那么则需要在一个局域网中或一个路由器中才可以做到 接下来就是具体的操作检查sqlserver数据库是否允许远程连接 具体操作为 (1)打开数据库,用本地帐户登录,右击第一个选项, ...
- @ManyToOne和@OneToMany 注解
(1)ManyToOne(多对一)单向:不产生中间表,但可以用@Joincolumn(name=" ")来指定生成外键的名字,外键在多的一方表中产生! (2)OneToMany( ...
- squid代理缓存服务
man.linuxde.net 1.squid是Linux系统中的代理缓存服务,通常用作WEB网站的前置缓存服务,能够代替用户向网站服务器请求页面数据并进行缓存. 2.squid服务特点:配置简单.效 ...
- 【总结】 BZOJ前100题总结
前言 最近发现自己trl,所以要多做题目但是Tham布置的题目一道都不会,只能来写BZOJ HA(蛤)OI 1041 复数可以分解成两个点,所以直接把\(R^2\)质因数分解一下就可以了,注意计算每一 ...
- python中的列表和元组
1. 什么是列表 定义: 能装对象的对象 在python中使用[]来描述列表, 内部元素用逗号隔开. 对数据类型没有要求,列表存在索引和切片. 和字符串是一样的. 2.相关的增删改查操作 切片 列表和 ...