Created
August 11, 2016 02:02
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /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