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

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

问题描述

我已经将我的 Django 网站放到了我的网络服务器上,并使用 apache2 和 mod_wsgi 进行了设置.大部分时间一切正常,但有时它只会给出无法导入模块的错误(通常来自我的视图文件).但是,这不是该模块的问题,因为它通常可以工作,例如,我会收到一次错误无法从模块导入 classname",然后重新加载页面并且它工作正常,我会说大约每 10 个页面加载中就有 1 个发生这种情况,而且这只是随机的,因为它会发生在我网站上的任何页面上.

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.

我尝试重新启动 apache2,重新启动服务器,但问题仍然存在.我已经在不同的客户端机器上尝试过,清除用户缓存等,但问题仍然存在.我不知道可能会发生什么,也许某种缓存有助于防止这种情况发生,因为服务器似乎只是遇到了有时无法完全处理请求的问题.我正在使用服务器上没有太多内存的云设置,所以这可能是问题所在?任何建议表示赞赏

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.

您可以尝试替代 WSGI 脚本文件,如下所述:

You can try alternate WSGI script file as documented in:

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

问题是开发服务器与使用 WSGI 的正确部署系统之间的差异,还是用户没有正确处理导入并导致订单依赖性甚至导入周期,尚无定论.问题可能只有在 URL 以特定顺序访问时才会出现,因此为什么会随机出现问题.

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.

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

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