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")
  1. call settings.configure()
from django.conf import settings

关于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.

仅有 1 条评论
  1. 没用