Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: cannot import name formset_factory

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
like image 335
aemdy Avatar asked Dec 21 '22 16:12

aemdy


1 Answers

You are importing it from the wrong location, you need to import from django.forms.formsets instead:

from django.forms.formsets import formset_factory

See the Formsets documentation.

like image 170
Martijn Pieters Avatar answered Dec 26 '22 18:12

Martijn Pieters