Supposing you have setup a django project, and the settings file is in an app named main, this is how you initialize your code
import os, sys
# Setup environ
sys.path.append(os.getcwd())
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "main.settings")
# Setup django
imp...