I have a Python script as follows:

from django.db import transaction
from django.contrib.auth.models import User
from flow.models import States, Types, Docs, Logs

if __name__ == '__main__':
    with transaction.atomic():
        models.Logs.objects.all().delete()
        models.Docs.objects.all().delete()
        models.States.objects.all().delete()
        models.Types.objects.all().delete()
        models.User.objects.all().delete()
        user1 = User.objects.create_user('john', 'xxx...@gmail.com', 
'johnpass')
        user1.save()

When I run this in IDLE I get the following error:

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 38, in 
_setup
    settings_module = os.environ[ENVIRONMENT_VARIABLE]
  File "C:\Python34\lib\os.py", line 651, in __getitem__
    raise KeyError(key) from None
KeyError: 'DJANGO_SETTINGS_MODULE'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Daniel\Documents\Python\cresta\flow\test_data.py", line 7, 
in <module>
    from django.contrib.auth.models import User
  File "C:\Python34\lib\site-packages\django\contrib\auth\__init__.py", 
line 6, in <module>
    from django.middleware.csrf import rotate_token
  File "C:\Python34\lib\site-packages\django\middleware\csrf.py", line 14, 
in <module>
    from django.utils.cache import patch_vary_headers
  File "C:\Python34\lib\site-packages\django\utils\cache.py", line 26, in 
<module>
    from django.core.cache import get_cache
  File "C:\Python34\lib\site-packages\django\core\cache\__init__.py", line 
69, in <module>
    if DEFAULT_CACHE_ALIAS not in settings.CACHES:
  File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 54, in 
__getattr__
    self._setup(name)
  File "C:\Python34\lib\site-packages\django\conf\__init__.py", line 47, in 
_setup
    % (desc, ENVIRONMENT_VARIABLE))
django.core.exceptions.ImproperlyConfigured: Requested setting CACHES, but 
settings are not configured. You must either define the environment 
variable DJANGO_SETTINGS_MODULE or call settings.configure() before 
accessing settings.

How do I configure these settings?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/9b3a4974-26fd-4229-a3bf-7d7ce28dbdfe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to