我在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
干净地构建基于类的视图?