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.

最新文章

  1. 新项目的CQRS设计
  2. 还有 3 天,苹果就要关上 HTTP 大门了
  3. Java学习随笔4:Java的IO操作
  4. 【Jenkins】jenkins简单搭建并执行任务
  5. 工作中遇到的问题--使用DTO减少数据字段
  6. hdu 3111 DLX解数独
  7. VS2010升级VS2012必备(MVC4 WebPage2.0 Razor2.0资料汇集)
  8. Java web.xml加载顺序
  9. 在javaweb中通过servlet类和普通类读取资源文件
  10. Python爬虫 Cookie的使用
  11. html 选择器之属性选择器
  12. JavaScript Html页面加载完成
  13. Unity UGUI图文混排源码(一)
  14. 把.Net开发环境迁移到Linux上去
  15. vue 子组件调用父组件的方法
  16. Akka-CQRS(4)- CQRS Writer Actor 示范
  17. HTML4到HTML5
  18. Linux下7z工具安装
  19. 第七次Scrum冲刺
  20. 我的第一个博客——Fragment遇到的问题

热门文章

  1. ViewController的属性
  2. CentOS 最新版的下载地址 + 版本选择详解
  3. Ansible 笔记 (1) - 安装和配置
  4. 安装及运行 RabbitMQ 服务器 (windows)
  5. Codeforces788A Functions again 2017-04-12 18:22 56人阅读 评论(0) 收藏
  6. java并发编程实战:第三章----对象的共享
  7. 深刻理解Java编程的7个例子
  8. [label][JavaScript][The Defined Guide of JavaScript] 如何声明变量
  9. java向数据库插入N条数据
  10. Linux 下 Memcached 缓存服务器安装配置