Django:无法导入名称formset_factory

时间:2012-09-10 15:58:17

标签: python django pycharm python-import

我无法从django导入formset_factory。

这是追溯:

from django.forms import formset_factory


Environment:


Request Method: GET
Request URL: http://localhost:8000/forma/

Django Version: 1.4.1
Python Version: 2.7.3
Installed Applications:
['debug_toolbar',
 'django_extensions',
 'gunicorn',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'internal',
 'internal.customers',
 'internal.customers.natural',
 'internal.customers.entity',
 'internal.farmsteads',
 'internal.photos',
 'internal.offers',
 'internal.orders',
 'internal.places',
 'internal.statuses',
 'internal.extra_information',
 'internal.properties',
 'internal.calendar',
 'internal.newsletters',
 'aemdyutils',
 'tinymce']
Installed Middleware:
('debug_toolbar.middleware.DebugToolbarMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware')


Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  101.                             request.path_info)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  300.                     sub_match = pattern.resolve(new_path)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in resolve
  209.             return ResolverMatch(self.callback, args, kwargs, self.name)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in callback
  216.         self._callback = get_callable(self._callback_str)
File "/usr/local/lib/python2.7/dist-packages/django/utils/functional.py" in wrapper
  27.         result = func(*args)
File "/usr/local/lib/python2.7/dist-packages/django/core/urlresolvers.py" in get_callable
  92.                 lookup_view = getattr(import_module(mod_name), func_name)
File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py" in import_module
  35.     __import__(name)
File "/home/aemdy/projects/rezervavau_v2/internal/orders/views.py" in <module>
  3. from django.forms import formset_factory

Exception Type: ImportError at /forma/
Exception Value: cannot import name formset_factory

1 个答案:

答案 0 :(得分:11)

您要从错误的位置导入它,您需要从django.forms.formsets导入:

from django.forms.formsets import formset_factory

请参阅Formsets documentation