Standalone script with Django

I am going to run external script by invoking Django module, db models etc.

Here the refernece link from django official docs.:

However, for the quote of website which is not working for me:

import django
from django.conf import settings
from myapp import myapp_defaults

settings.configure(default_settings=myapp_defaults, DEBUG=True)

# Now this script or any imported module can use any part of Django it needs.
from myapp import models

simply I am using following code instead:

#!/usr/bin/env python3

import os
import sys

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "saltmgt.saltmgt.settings")
if __name__ == '__main__':
    import django
    from autocd.models import *
    <<your scripts>>

which is working fine for me.

Enjoy 🙂

other refernece links which helps:



Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Leave a Reply

Your email address will not be published. Required fields are marked *