django filer - ImportError: cannot import name mixins

怎甘沉沦 提交于 2019-12-11 01:54:34

问题


I have a django 1.4 installation and I have django-cms running. I'm try to install filer but when I syncdb or runserver I keep having this error.

 from filer.models import mixins
 ImportError: cannot import name mixins

In my setting.py I have:

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
'cms', 
'mptt',
'menus', 
'south',
'sekizai', 
'ftlom',
#'cms.plugins.text',
#'cms.plugins.picture',
'cmsplugin_twitter',
'easy_thumbnails',
'filer',
#'ordered_model',
#'cmsplugin_filer_file',
#'cmsplugin_filer_folder',
'cmsplugin_filer_image',
#'cmsplugin_gallery',
'cms.plugins.video',
#'gunicorn',


# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',

)

If I remove filer and all its plugins my site works fine. What could possibly cause the problem? thanks

Traceback :

Validating models...

Unhandled exception in thread started by <bound method Command.inner_run of     <django.contrib.staticfiles.management.commands.runserver.Command object at 0x1050d4fd0>>
Traceback (most recent call last):
File "/Users/Alex/.virtualenvs/FTLOM/lib/python2.7/site-   packages/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/Users/Alex/.virtualenvs/FTLOM/lib/python2.7/site-packages/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/Users/Alex/.virtualenvs/FTLOM/lib/python2.7/site-packages/django/core/management/validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/Users/Alex/.virtualenvs/FTLOM/lib/python2.7/site-packages/django/db/models/loading.py", line 158, in get_app_errors
self._populate()
File "/Users/Alex/.virtualenvs/FTLOM/lib/python2.7/site-packages/django/db/models/loading.py", line 67, in _populate
self.load_app(app_name)
File "/Users/Alex/.virtualenvs/FTLOM/lib/python2.7/site-packages/django/db/models/loading.py", line 88, in load_app
models = import_module('.models', app_name)
File "/Users/Alex/.virtualenvs/FTLOM/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/Alex/.virtualenvs/FTLOM/lib/python2.7/site-packages/filer/models/__init__.py", line 2, in <module>
from filer.models.clipboardmodels import *
File "/Users/Alex/.virtualenvs/FTLOM/lib/python2.7/site-packages/filer/models/clipboardmodels.py", line 5, in <module>
from filer.models import filemodels
File "/Users/Alex/.virtualenvs/FTLOM/lib/python2.7/site-packages/filer/models/filemodels.py", line 8, in <module>
from filer.models import mixins

ImportError: cannot import name mixins

This my pip freeze :

Django==1.4
PIL==1.1.7
South==0.8.1
cmsplugin-filer==0.9.5
cmsplugin-twitter==1.0.4
django-classy-tags==0.4
django-cms==2.4.1
django-filer==0.9.3
django-mixins==0.0.10
django-mptt==0.5.2
django-ordered-model==0.2.0
django-polymorphic==0.5
django-sekizai==0.7
easy-thumbnails==1.3
gunicorn==17.5
html5lib==1.0b1
six==1.3.0
wsgiref==0.1.2

回答1:


You are running Django version 1.4.1 or lower, which you can check by any of these methods:

  1. on the bash

    pip freeze | grep Django | awk 'BEGIN { FS = "==" } ; { print $2 }'

  2. on the bash, if django has been properly set to the Linux path

    django-admin --version

  3. on the django.shell

    import django
    django.VERSION #or
    django.get_version()

Although not specifically asserted, it seems that django-filer 0.9.x is incompatible with django versions below 1.4.1

Fixing the mixin problem won't help:

First off, django-mixins is a different project, and its namespace not used nor conflicting.
django-filer contains a module mixins, which is more of a stump for Icon-loading at the moment, rather than anything of genuine importance. You could change the foldermodels.py and filemodels.py:

from filer.models import mixins
=> to
import filer.models.mixins

Yet after resolving the mixinsissue, you will still struggle with import difficulties of django.utils.six

Part of the reason is that utils.six, a Python 2/3 compatibility layer has only recently been added to Django 1.4.2

Solution

You can see from https://github.com/stefanfoulis/django-filer/blob/develop/HISTORY , that installing version 0.8.7 could work. First remove the newer django-filer package though.

 pip uninstall django-filer
 easy_install django-filer==0.8.7

Indeed this version works well on Django version 1.4.1

Note: If you installed django-mixins by mistake, remove it as well. It is good practice to not keep unused and non-dependent django-modules around.




回答2:


I ran into the same problem. The problem was hard to find but simple to solve.

After installing django-polymorphic, everything worked fine.



来源:https://stackoverflow.com/questions/17949389/django-filer-importerror-cannot-import-name-mixins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!