django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG... 错误的两种解决办法

在网上取数据,用 Django 存储的时候遇到的错误提示
django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

根据提示给出的两种办法:

  1. define the environment variable DJANGO_SETTINGS_MODULE

    import os
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "你的project.settings")
  2. call settings.configure()

    from django.conf import settings
    settings.configure(DEBUG=True)

关于call settings.configure()官方的说法:

In some cases, you might want to bypass the DJANGO_SETTINGS_MODULE
environment variable. For example, if you’re using the template system
by itself, you likely don’t want to have to set up an environment
variable pointing to a settings module.

Exactly what I want to do.

已有 2 条评论
  1. 没用

  2. [...]转发:django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG… 错误的两种解决办法 – Code Life of gladuo[...]

添加新评论