如何正确解决" AppRegistryNotReady:尚未加载应用。"?

时间:2016-08-15 01:02:11

标签: python django django-forms django-class-based-views

我在Django中遇到了一个问题。

  • views.py我需要从forms.py
  • 导入表单
  • 此视图是基于类的视图,这意味着表单位于模块上下文中,原因是:

    class SomeClassBasedView(FormView):
        form_class = MyModelForm
    
  • forms.py之外,我需要从models.py
  • 导入模型

这意味着(我假设)在正确加载App之前加载了models.py,导致:

  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 237, in get_containing_app_config
    self.check_apps_ready()
  File "/usr/local/lib/python2.7/dist-packages/django/apps/registry.py", line 124, in check_apps_ready
    raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

如何使用ModelForm干净地构建基于类的视图?

0 个答案:

没有答案