Django报错:django.core.exceptions.ImproperlyConfigured的处理办法

Django报错:django.core.exceptions.ImproperlyConfigured的处理办法

Django报错: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 settings.configure() before accessing settings.,如何解决?

说一个应用的场景,因为程序运行的时候一般是要在特定的环境特定的场景下会有不一样的表现的,那么CK实在做什么的时候遇到这个类型的错误的呢?

CK是在运行Sf上一个前辈的代码的时候出现如此错误的,这个前辈的文章的题目是Python爬虫建站入门手记-第三章(采集入库),之前的许多错误都已经解决,但是在运行到:

1.>>> from web.models import Answer, Question, Tag
2.的时候出现了错误

错误提醒就是:

1.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 settings.configure() before accessing settings.

其实出现这个错误的时候呢我们有两个解决方法:
一、

  • import os
  • os.environ[‘DJANGO_SETTINGS_MODULE‘] = ‘mysite.settings‘ (因为我的项目是web,所以此处的mysite.setting应为web.settings)

二、
在运行程序之前,先在shell中输入如下的命令:
set DJANGO_SETTINGS_MODULE=mysite.settings(此处的mysite应为我的项目,web,即应写为web.settings)

或者直接将之前第一种的解决方法的代码写在main文件中
Main代码中增加;
import os
os.environ[‘DJANGO_SETTINGS_MODULE’] = ‘mysite.settings’ # 此处的mysite应为web

ckhero

发表评论

To create code blocks or other preformatted text, indent by four spaces:

    This will be displayed in a monospaced font. The first four 
    spaces will be stripped off, but all other whitespace
    will be preserved.
    
    Markdown is turned off in code blocks:
     [This is not a link](http://example.com)

To create not a block, but an inline code span, use backticks:

Here is some inline `code`.

For more help see http://daringfireball.net/projects/markdown/syntax