django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured
<p>Iâm using Django 1.10 with Python 2.7. I have a problem running a Python script that uses Django models.</p>

<pre><code> $ python contentui_app/content-util.py --sig

    Traceback (most recent call last):
      File "contentui_app/content-util.py", line 9, in &lt;module&gt;
        from models import *
      File "/var/django-project/contentui/contentui_app/models.py", line 12, in &lt;module&gt;
        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.
</code></pre>

#

<p>this is the code</p>

<pre><code>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 *
</code></pre>

<p>This is caused when you donât initialize Django. Try running this:</p>

<pre><code>from django.conf import settings
from contentui import settings
settings.configure(settings)
</code></pre>

<p>before the rest of your code.</p>

python django