4

I have trouble importing formset_factory from django.

Here's the traceback:

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
4

1 回答 1

11

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

from django.forms.formsets import formset_factory

请参阅表单集文档

于 2012-09-10T16:00:51.850 回答