使用Apache2(mod_wsgi)的Django问题有时候是“无法从模块导入”没有明显的理由 [英] Problem with Django using Apache2 (mod_wsgi), Occassionally is "unable to import from module" for no apparent reason
问题描述
我已经尝试重新启动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屋!