pythoncharm 中解决启动server时出现 “django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured”的错误
背景介绍
最近,尝试着用pythoncharm 这个All-star IDE来搞一搞Django,于是乎,下载专业版,PJ等等一系列操作之后,终于得偿所愿。可以开工了。
错误
在园子里找了一篇初学者的教程,按照教程上面的指导,一步一步往下走,一路上都很顺利。但是到了启动django server的时候出现了意外。
错误信息如下:
/home/ct/PycharmProjects/mysite/venv/bin/python /home/ct/PycharmProjects/mysite/manage.py runserver 127.0.0.1:
Traceback (most recent call last):
File "/home/ct/PycharmProjects/mysite/manage.py", line , in <module>
execute_from_command_line(sys.argv)
File "/home/ct/PycharmProjects/mysite/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line , in execute_from_command_line
utility.execute()
File "/home/ct/PycharmProjects/mysite/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line , in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ct/PycharmProjects/mysite/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line , in run_from_argv
self.execute(*args, **cmd_options)
File "/home/ct/PycharmProjects/mysite/venv/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line , in execute
super(Command, self).execute(*args, **options)
File "/home/ct/PycharmProjects/mysite/venv/local/lib/python2.7/site-packages/django/core/management/base.py", line , in execute
output = self.handle(*args, **options)
File "/home/ct/PycharmProjects/mysite/venv/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line , in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "/home/ct/PycharmProjects/mysite/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line , in __getattr__
self._setup(name)
File "/home/ct/PycharmProjects/mysite/venv/local/lib/python2.7/site-packages/django/conf/__init__.py", line , in _setup
% (desc, ENVIRONMENT_VARIABLE)) django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Process finished with exit code
分析原因
最初,分析原因猜测是Django的安装出了问题; 但是,使用 terminal来启动django, 一切正常啊。
ct@ubuntu:~/PycharmProjects/mysite$ python manage.py runserver 127.0.0.1:
Performing system checks... System check identified no issues ( silenced). You have unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions.
Run 'python manage.py migrate' to apply them. April , - ::
Django version 1.11, using settings 'mysite.settings' Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
思考了以后,感觉还是 pythoncharm 里,关于django的设置出了问题。于是打开IDE中的配置,发现缺失了 “DJANGO_SETTINGS_MODULE” 的配置

解决方法
顺着这个思路,一直找解决方案,终于找到了如何设置django项目的配置。
export DJANGO_SETTINGS_MODULE=mysite.settings
其实也就是添加环境变量罢了,只不过在pythoncharm中,我们需要将环境变量添加到IDE里面。。。

点击OK后,再次在pythoncharm里运行项目,这次成功啦!!

参考资料:
https://stackoverflow.com/questions/26082128/improperlyconfigured-you-must-either-define-the-environment-variable-django-set
记录一下加深记忆的同时也希望能帮到其他人!! 感谢大家的收看, bye~~
pythoncharm 中解决启动server时出现 “django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured”的错误的更多相关文章
- 关于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 ...
- celery开启worker报错django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE o
其实挺简单的问题,但花了自己一个下午来解决,先是浏览各种博客,无果:没办法,然后去看celery官方文档,无果,近乎绝望,最后仔细看代码,找到问题所在(如下),自学狗这效率...... 下面是自己ta ...
- 解决:django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not 的方法
错误类型: 该错误是在在创建Django工程时出现遇到的错误 完整报错信息:(博文标题输入长度有限制) django.core.exceptions.ImproperlyConfigured: Req ...
- django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE的解决办法(转)
在python的开发中,遇到了这个错误: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TA ...
- python基于Django框架编译报错“django.core.exceptions.ImproperlyConfigured”的解决办法?
下面是我具体遇到的问题和解决方法: 错误详细信息: django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_IND ...
- django中执行py报错Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured
https://blog.csdn.net/heybob/article/details/49684261 django代码下面直接run的时候报错: django.core.exceptions.I ...
- Django2.2连接mysql数据库出现django.core.exceptions.ImproperlyConfigured: mysqlclient 1.3.3 or newer is required; you have 0.7.11.None问题
在使用Django2.2开发的时候,想要使用mysql数据库,在settings.py文件中更改命令: DATABASES = { 'default': { 'ENGINE': 'django.db. ...
随机推荐
- [转][RabbitMQ+Python入门经典] 兔子和兔子窝
[转][RabbitMQ+Python入门经典] 兔子和兔子窝 http://blog.csdn.net/linvo/article/details/5750987 RabbitMQ作为一个工业级的消 ...
- JDK1.8源码(三)——java.lang.String 类
String 类也是java.lang 包下的一个类,算是日常编码中最常用的一个类了,那么本篇博客就来详细的介绍 String 类. 1.String 类的定义 public final class ...
- cesium Animation显示系统时间
var d = new Date(); var hour = 0 - d.getTimezoneOffset(); viewer.animation.viewModel.timeFormatter = ...
- vue小demo易错点总结
1.在使用<transiton>添加过渡效果时,对应的标签需使用<router-link>,否则,transition不会达到应有的效果. 2.在路由文件里获取根实例时,需通过 ...
- Mycat 介绍
Mycat 是什么 Mycat是什么?从定义和分类来看,它是一个开源的分布式数据库系统,是一个实现了 MySQL协议的的Server,前端用户可以把它看作是一个数据库代理,用 MySQL客户端工具和命 ...
- 笔记:Maven 项目基本配置
Maven 的基本设置包含项目基本信息和项目信息,基本信息主要用于设置当前包的归属项目.当前项目等,配置文件结构如下: <project xmlns="http://maven.apa ...
- Acer Aspire E1 471G 加装SSD+机械盘后无法启动的问题
老笔记本 Acer Aspire E1 471G 加装了一块 SSD 作为系统盘(win10),原机械盘格式化后,装在光驱托架上作为数据盘. 可能会出现: 系统无法启动,显示找不到启动设备,并且在F2 ...
- WebPack的安装
一.前提因为webpack是一个基于node的项目,所以首先需要确保你的电脑里面已经安装了node.js,以及npm.在这里我使用的版本是:node:v5.8.0 ,npm:3.7.3,若是版本问题, ...
- Vue常用开源项目汇总
前言:Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架.与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用.Vue 的核心库只关注视图层,不仅易于上手,还 ...
- Redis进阶实践之十九 Redis如何使用lua脚本
一.引言 redis学了一段时间了,基本的东西都没问题了.从今天开始讲写一些redis和lua脚本的相关的东西,lua这个脚本是一个好东西,可以运行在任何平台上,也可以嵌入 ...