Django_cms Incorrectly configured: cms.middleware.media middleware import error

I am moving an application that uses django_cms from one server where everything works, with another and for the last 4 hours I have tried to find the cause of this error. Suggestions are very welcome!

mod_wsgi (pid=21972): Exception occurred within WSGI script '/var/www/vhosts/compdoctest.com/django/compdoc/django.wsgi'. Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py", line 230, in __call__ self.load_middleware() File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py", line 42, in load_middleware raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e)) ImproperlyConfigured: Error importing middleware cms.middleware.media: "No module named media" 

The violation line is the last in the middleware list in settings.py

 MIDDLEWARE_CLASSES = ( 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'cms.middleware.page.CurrentPageMiddleware', 'cms.middleware.user.CurrentUserMiddleware', 'cms.middleware.multilingual.MultilingualURLMiddleware', 'cms.middleware.media.PlaceholderMediaMiddleware', ) 

If I delete the final line, then the code continues and crashes later, saying that this element is required in the middleware.

I am using a slightly different version of django, 1.2.1 final on the old working server and 1.2.3 final on the new server.

All I tried:

  • The same version of django_cms - 2.1.0 beta 3 -, which was used on the old server
  • The latest version on github is 2.1.0.beta2-550 Entering cms, mptt, menu, publisher folders in
  • app From python importing
  • googled (I don't have the same problem as me)
  • middleware file (no problem)

python discovery result:

 python manage.py shell Python 2.5.2 (r252:60911, Jan 20 2010, 23:14:04) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> import cms.middleware.media >>> cms.middleware.media.__file__ '/var/www/vhosts/compdoctest.com/django/compdoc/cms/middleware/media.pyc' >>> from django.forms.widgets import Media >>> import cms.middleware.media >>> 
+7
django django-cms
source share
2 answers

Thanks to my friend Bartosz Ptaszinski for pointing me in the right direction. It was a problem of the way. This is added to the top of the settings.py file, and all this magic started to work.

sys.path.insert (0, '/ path_to_app / app /')

And as he pointed out:

The exception that occurred in the WSGI script means that the path while working under the web server was incorrect, this is a completely different environment than the manage.py shell

+4
source share

I had the same problem. But since this only happens when using mod_wsgi, another solution adds the path to the apache configuration (rather than editing the syspath inside the setting.py parameter):

  # mod_wsgi settings WSGIDaemonProcess name user=user group=group python-path=/app_path/app/:/app_path/lib/python2.6/site-packages/:/app_path/ WSGIProcessGroup polykum 

Including site packages in the path is also shown in the Jon Black example.

0
source share

All Articles