Django: AppRegistryNotReady()

Python: 2.7; Django: 1.7; Mac 10.9.4

Je suis en suivant le tutoriel de Le Tango avec Django

Au Chapitre 5, le tutoriel pour apprendre à créer une population de script, qui permet de créer automatiquement des données pour la base de données pour la facilité de développement.

J'ai créé un populate_rango.py au même niveau de manage.py.

Voici l'populate_rango.py:

import os
def populate():
python_cat = add_cat('Python')
add_page(
cat=python_cat,
title="Official Python Tutorial",
url="http://docs.python.org/2/tutorial/"
)
add_page(
cat=python_cat,
title="How to Think like a Computer Scientist",
url="http://www.greenteapress.com/thinkpython/"
)
add_page(
cat=python_cat,
title="Learn Python in 10 Minutes",
url="http://www.korokithakis.net/tutorials/python/"
)
django_cat = add_cat("Django")
add_page(
cat=django_cat,
title="Official Django Tutorial",
url="https://docs.djangoproject.com/en/1.5/intro/tutorial01/"
)
add_page(
cat=django_cat,
title="Django Rocks",
url="http://www.djangorocks.com/"
)
add_page(
cat=django_cat,
title="How to Tango with Django",
url="http://www.tangowithdjango.com/"
)
frame_cat = add_cat("Other Frameworks")
add_page(
cat=frame_cat,
title="Bottle",
url="http://bottlepy.org/docs/dev/"
)
add_page(
cat=frame_cat,
title="Flask",
url="http://flask.pocoo.org"
)
for c in Category.objects.all():
for p in Page.objects.filter(category=c):
print "- {0} - {1}".format(str(c), str(p))
def add_page(cat, title, url, views=0):
p = Page.objects.get_or_create(category=cat, title=title, url=url, views=views)[0]
return p
def add_cat(name):
c = Category.objects.get_or_create(name=name)[0]
return c
if __name__ == '__main__':
print "Starting Rango population script..."
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tangle.settings')
from rango.models import Category, Page
populate()

Puis-je exécuter python populate_rango.py à l'aérogare, au niveau de manage.py, AppRegistryNotReady() est soulevée:

django.core.exceptions.AppRegistryNotReady

Puis je l'ai googlé, a trouvé quelque chose comme cette:

Standalone scripts
If youre using Django in a plain Python script  rather than a management command  and you rely on the DJANGO_SETTINGS_MODULE environment variable, you must now explicitly initialize Django at the beginning of your script with:
>>> import django
>>> django.setup()
Otherwise, you will hit an AppRegistryNotReady exception.

Et je n'ai toujours aucune idée de ce que je dois faire, peut-on aider? Thx!!!

InformationsquelleAutor user2988464 | 2014-07-17