Skip to content

Instantly share code, notes, and snippets.

@gleydson404
Created August 11, 2016 02:02
Show Gist options
  • Save gleydson404/0d9aa3e8411e2f53d3e0938c87452c17 to your computer and use it in GitHub Desktop.
Save gleydson404/0d9aa3e8411e2f53d3e0938c87452c17 to your computer and use it in GitHub Desktop.
If you are having problems like "django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet", this could be helpfull. Credits to http://www.dangtrinh.com/2014/11/how-to-avoid-models-arent-loaded-yet.html
#! /usr/bin/env python
def setup_environment():
pathname = os.path.dirname(sys.argv[0])
sys.path.append(os.path.abspath(pathname))
sys.path.append(os.path.normpath(os.path.join(os.path.abspath(pathname), '../')))
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'
setup_environment()
import django
django.setup()
"""
Don't forget to import os, and sys to works.
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment