使用Apache2(mod_wsgi)的Django问题有时候是“无法从模块导入”没有明显的理由 [英] Problem with Django using Apache2 (mod_wsgi), Occassionally is "unable to import from module" for no apparent reason

查看:135
本文介绍了使用Apache2(mod_wsgi)的Django问题有时候是“无法从模块导入”没有明显的理由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经把我的Django网站放到了我的网络服务器上,并使用apache2和mod_wsgi进行设置。一切都可以正常工作,但是偶尔会给出不能导入模块的错误(通常来自我的视图文件)。但是,该模块通常不起作用,例如,我将从模块中获取错误无法从模块导入 classname ,然后重新加载该页面,它可以正常工作,我会说这是大约1/10页的负载,发生这种情况,它只是随机的,因为它会发生在我网站上的任何页面。



我已经尝试重新启动apache2,重新启动服务器,问题依然存在。我已经在不同的客户端机器上尝试过,清除用户缓存等,但问题仍然存在。我不知道该做什么,也许某种缓存有助于防止这种情况,因为服务器似乎只是有一个问题,有时无法完全处理请求。我正在使用云设置在服务器上没有太多的内存,所以也许这是问题?任何意见都不胜感激

解决方案

大部分时间都在运行,因为你可能有一个多进程配置,只有一个进程受影响。



您可以尝试备用WSGI脚本文件,如下所示:



http://blog.dscpl.com.au/2010/ 03 / improved-wsgi-script-for-use-with.html



陪审团仍然认为问题是开发服务器之间的区别以及使用WSGI的正确部署系统,还是用户是否正确处理导入并导致订单依赖关系甚至导入周期。 URL可能只有在某些顺序访问时才出现,因此为什么随机可能发生。


I have put my Django web site up to my web server and have it set up using apache2 and mod_wsgi.. everything works fine most of the time but occasionally it will just give the error that it can't import a module (usually from my views file). However, it's not an issue with that module as it usually works, for example, I will get the error "Cannot import classname from module" once, then reload the page and it works fine, I would say it's about 1 in 10 page loads where this occurs and it's just random as it will happen for any page on my site.

I have tried restarting apache2, restarting the server but the issue persists. I have tried it on different client machines, clearing out the user cache, etc but the issue persists. I don't know what might be doing this, would perhaps some sort of caching help prevent this as it seems that the server is just having an issue with sometimes not being able to fully process the request. I am using a cloud set up with not much memory on the server so maybe this is the problem? Any advice is appreciated

解决方案

It is working most of the time because you likely have a multi process configuration and only one of the processes is affected.

You can try alternate WSGI script file as documented in:

http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html

The jury is still out as to whether the issue is the differences between development server and proper deployment systems using WSGI, or whether it is users not handling imports properly and causing order dependencies or even import cycles. Problems possibly only come up when URL visited in certain order and thus why random as to when it can happen.

这篇关于使用Apache2(mod_wsgi)的Django问题有时候是“无法从模块导入”没有明显的理由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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