Search code examples
pythondjangotastypie

Import Django settings from external script


I have a python script within my Django project designed to run seperate from the Django app. I want to use the settings.py on my Django App how can I do that.

When I try to import

from django.conf import settings

i get

ImportError: No module named DjangoTastypie.settings

My project Structure

enter image description here

I am running using eclipse-> Run as python


Solution

  • Read https://docs.djangoproject.com/en/1.9/topics/settings/#calling-django-setup-is-required-for-standalone-django-usage

    So you basically will need to put this at the beginning of your script

    import os
    import django
    from django.conf import settings
    
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')
    django.setup()