django.core.exceptions.ImproperlyConfigured:请求设置DEFAULT_INDEX_TABLESPACE,但未配置设置

时间:2016-08-25 16:15:10

标签: python django

我正在使用Django 1.10和Python 2.7。我在运行使用Django模型的Python脚本时遇到问题。

 $ python contentui_app/content-util.py --sig

    Traceback (most recent call last):
      File "contentui_app/content-util.py", line 9, in <module>
        from models import *
      File "/var/django-project/contentui/contentui_app/models.py", line 12, in <module>
        class AuthGroup(models.Model):
      File "/var/django-project/contentui/contentui_app/models.py", line 13, in AuthGroup
        name = models.CharField(unique=True, max_length=80)
      File "/usr/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 1043, in __init__
        super(CharField, self).__init__(*args, **kwargs)
      File "/usr/local/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 166, in __init__
        self.db_tablespace = db_tablespace or settings.DEFAULT_INDEX_TABLESPACE
      File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 53, in __getattr__
        self._setup(name)
      File "/usr/local/lib/python2.7/site-packages/django/conf/__init__.py", line 39, in _setup
        % (desc, ENVIRONMENT_VARIABLE))
    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.

这是代码

from django.conf import settings
settings.configure()
from optparse import OptionParser
from pprint import pprint
import sys, os, hashlib, re, datetime, inspect, time, string, django
sys.path.append("/var/alertlogic/django-project/contentui")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "contentui.settings")
django.setup()

from contentui_app.models import *

1 个答案:

答案 0 :(得分:0)

这是在你没有初始化Django时引起的。试试这个:

from django.conf import settings
from contentui import settings
settings.configure(settings)
在其余代码之前