Django: AppRegistryNotReady()

后端 未结 4 1079
梦毁少年i
梦毁少年i 2020-11-30 02:15

Python: 2.7; Django: 1.7; Mac 10.9.4

I\'m following the tutorial of Tango with Django

At Chapter 5, the tutorial teaches how to create a population script, w

4条回答
  •  再見小時候
    2020-11-30 02:55

    If you are using your django project applications in standalone scripts, in other words, without using manage.py - you need to manually call django.setup() first - it would configure the logging and, what is important - populate apps registry.

    Quote from Initialization process docs:

    setup()

    This function is called automatically:

    • When running an HTTP server via Django’s WSGI support.

    • When invoking a management command.

    It must be called explicitly in other cases, for instance in plain Python scripts.

    In your case, you need to call setup() manually:

    if __name__ == '__main__':
        print "Starting Rango population script..."
        os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tangle.settings')
    
        import django
        django.setup()
    
        populate()
    

    Also, this problem is described in detail in Troubleshooting section.

提交回复
热议问题