django_cms不正确配置:导入中间件cms.middleware.media导致错误 [英] django_cms ImproperlyConfigured: Error importing middleware cms.middleware.media

查看:143
本文介绍了django_cms不正确配置:导入中间件cms.middleware.media导致错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在移动一个使用django_cms的应用程序,这些应用程序使用一个服务器(其中一切工作)到另一个服务器,并且花了最后4个小时尝试找到导致此错误的原因。一个建议非常受欢迎!

  mod_wsgi(pid = 21972):WSGI脚本中出现异常/ var / www / vhosts / compdoctest的.com / django的/ compdoc / django.wsgi。 
追溯(最近的最后一次调用):
文件/usr/lib/python2.5/site-packages/django/core/handlers/wsgi.py,第230行,__call__
self.load_middleware()
文件/usr/lib/python2.5/site-packages/django/core/handlers/base.py,第42行,load_middleware
raise exceptions.ImproperlyConfigured(导入中间件%s时出错:%s'%(mw_module,e))
不正确的配置:导入中间件的错误cms.middleware.media:没有名为media的模块

违规行是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.p年龄.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.multilingual.MultilingualURLMiddleware',
'cms.middleware.media.PlaceholderMediaMiddleware',

如果我删除最后一行,那么代码继续下去,后来说该项是必需的在中间件中。



我使用稍微不同的版本的django,1.2.1最终在旧的工作服务器上,1.2.3最终在新服务器上。 >

所有我尝试过的东西:




  • 同样版本的django_cms - 2.1。 0 beta 3 - 在旧服务器上使用

  • github上的最新版本 - 2.1.0.beta2-550将cms,mptt,菜单,发布商文件夹放在

  • 应用程序从python导入

  • googled(没有人可以找到相同的问题)

  • 中间件文件直接(没问题)



结果在python中打开:

  python manage.py shell 
Python 2.5.2(r252:60911,2010年1月20日,23:14:04)
[GCC 4.2.4(Ubuntu 4.2.4-1ubuntu3)] on linux2
输入help,copyright,credits或license了解更多信息。
(InteractiveConsole)
>>> import cms.middleware.media
>>> cms.middleware.media .__ file__
'/var/www/vhosts/compdoctest.com/django/compdoc/cms/middleware/media.pyc'
>>>从django.forms.widgets import Media
>>> import cms.middleware.media
>>>


解决方案

感谢我的朋友Bartosz Ptaszynski指出我正确的方向在这一个。这是一个路径问题。将它添加到settings.py文件的顶部,所有这些都是神奇地开始工作。



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

正如他指出的那样:



WSGI脚本中发生异常意味着在Web服务器下运行的路径是错误的,它是一个完全不同于manage.py shell


的环境

I'm moving an application that uses django_cms from one server, where everything worked, to another and have spent the last 4 hours trying to find the cause of this error. A suggestions 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 offending line is the last one 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 remove the final line then the code continues and falls over later saying that item is required in middleware.

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

All the things I've tried:

  • The same version of django_cms - 2.1.0 beta 3 - that was used on the old server
  • The latest version on github - 2.1.0.beta2-550 Putting the cms, mptt, menus, publisher folders in the
  • app From python importing the
  • googled (nobody having the same problem that I can find)
  • middleware file directly (no problem)

result of opening in python:

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
>>> 

解决方案

Thanks to my friend Bartosz Ptaszynski for pointing me in the right direction on this one. It was a path problem. Added this to the top of the settings.py file and it all magically started working.

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

And as he pointed out:

Exception occurred within WSGI script means that the path while running under the web server was wrong it's a completely different environment than the manage.py shell

这篇关于django_cms不正确配置:导入中间件cms.middleware.media导致错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆