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_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的更多相关文章

  1. 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 ...

  2. pythoncharm 中解决启动server时出现 “django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured”的错误

    背景介绍 最近,尝试着用pythoncharm 这个All-star IDE来搞一搞Django,于是乎,下载专业版,PJ等等一系列操作之后,终于得偿所愿.可以开工了. 错误 在园子里找了一篇初学者的 ...

  3. 关于Django报错django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configure

    报错代码:django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but se ...

  4. 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, ...

  5. 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 ...

  6. django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)

    在python的开发中,遇到了这个错误: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TA ...

  7. 解决:django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not 的方法

    错误类型: 该错误是在在创建Django工程时出现遇到的错误 完整报错信息:(博文标题输入长度有限制) django.core.exceptions.ImproperlyConfigured: Req ...

  8. python基于Django框架编译报错“django.core.exceptions.ImproperlyConfigured”的解决办法?

    下面是我具体遇到的问题和解决方法: 错误详细信息: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_IND ...

  9. 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 ...

随机推荐

  1. nginx 集群介绍

    nginx 集群介绍 完成一次请求的步骤 1)用户发起请求 2)服务器接受请求 3)服务器处理请求(压力最大) 4)服务器响应请求 缺点:单点故障 单台服务器资源有限 单台服务器处理耗时长 ·1)部署 ...

  2. .NET基础 (18)特性

    特性1 什么是特性,如何自定义一个特性2 .NET中特性可以在哪些元素上使用3 有哪几种方法可以获知一个元素是否申明某个特性4 一个元素是否可以重复申明同一个特性 特性1 什么是特性,如何自定义一个特 ...

  3. 通过HttpClient请求webService

    通过HttpClient请求webService 由于服务端是用webService开发的,android要调用webService服务获取数据,这里采用的是通过HttpClient发送post请求, ...

  4. (轉)CSS 单行溢出文本显示省略号...的方法(兼容IE FF)

    轉自:http://www.cnblogs.com/hlz789456123/archive/2009/02/18/1392972.html html代码:<div><p>&l ...

  5. EBS增加客制应用CUX:Custom Application

    1. 创建数据库文件和帐号 [root@ebs12vis oracle]# su - oracle[oracle@ebs12vis ~]$ sqlplus / as sysdba SQL*Plus: ...

  6. 6.nuget安装C#Driver驱动ZooKeeperNet

    一: C# 的Drivers   1. nuget上下载 zookeeper.Net   IWatcher是什么?: client 连接到 server 后,会在server上面注册一个watcher ...

  7. Postgres的TOAST技术

    一.介绍 首先,Toast是一个名字缩写,全写是The OverSized Attribute Storage Technique,即超尺寸字段存储技术,顾名思义,是说超长字段在Postgres的一个 ...

  8. TSQL--SQL SERVER 常用系统变量

    ----------全局变量select @@version as '版本';---------------------------返回当前数据库的版本信息 select APP_NAME ( ) a ...

  9. eCharts IE8兼容性问题

    使用Echart的图表柱状图,里面用了Float32Array,IE8下面会提示无法找到Float32Array,黄色叹号. 网上查找后使用如下方法解决:不明觉厉 在<head></ ...

  10. Android阻止AlertDialog关闭

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("测试" ...