简体   繁体   English

Django使用Apache2(mod_wsgi)的问题,有时无明显原因“无法从模块导入”

[英]Problem with Django using Apache2 (mod_wsgi), Occassionally is “unable to import from module” for no apparent reason

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). 我已经将Django网站放到我的Web服务器上,并使用apache2和mod_wsgi对其进行了设置。大多数情况下,一切正常,但偶尔会出现无法导入模块的错误(通常是从我的视图文件)。 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. 但是,该模块通常不会出现问题,例如,我将收到一次错误“无法从模块导入类名 ”,然后重新加载页面即可,并且可以正常工作,我说这大约是每10个页面加载一次发生这种情况的地方,只是随机的,因为我网站上的任何页面都会发生这种情况。

I have tried restarting apache2, restarting the server but the issue persists. 我尝试重新启动apache2,重新启动服务器,但问题仍然存在。 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: 您可以尝试以下方法中记录的备用WSGI脚本文件:

http://blog.dscpl.com.au/2010/03/improved-wsgi-script-for-use-with.html 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. 关于问题是开发服务器与使用WSGI的适当部署系统之间的差异,还是用户是否无法正确处理导入并导致订单依赖性甚至导入周期,尚无定论。 Problems possibly only come up when URL visited in certain order and thus why random as to when it can happen. 问题可能仅在URL以特定顺序访问时才会出现,因此为什么在何时可以随机访问它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django + mod_wsgi + apache2:ImportError:未命名模块<project> - Django + mod_wsgi + apache2: ImportError: No module named <project> Apache错误日志中的“ mod_wsgi:无法导入站点模块” - “mod_wsgi : Unable to import site module” in Apache Error Logs Django/mod_wsgi/Apache - mod_wsgi 没有使用为它编译的 Python 版本 - “ModuleNotFoundError: No module named 'math'” - Django/mod_wsgi/Apache - mod_wsgi is not using the Python version it was compiled for - “ModuleNotFoundError: No module named 'math' ” Django + Apache + mod_wsgi:导入错误 - Django + Apache + mod_wsgi: Import Error 无法使用 mod_wsgi 和 apache 部署 django - Unable to deploy django with mod_wsgi & apache 使用mod_wsgi在apache2上投放django时出错:没有名为设置的模块 - error serving django on apache2 with mod_wsgi: No module named settings Ubuntu-Python-Apache2-Mod_WSGI-Django:没有名为/ TypeError / TemplateSyntaxError /&#39;str&#39;对象的模块不可调用 - Ubuntu - Python - Apache2 - Mod_WSGI - Django: No module named / TypeError / TemplateSyntaxError / 'str' object is not callable Django尝试使用apache2 mod_wsgi - Django trying use apache2 mod_wsgi Django + mod_wsgi + apache2:服务器挂起 - Django + mod_wsgi + apache2: server hangs 使用mod_wsgi(Apache2)设置Django - Setting up Django with mod_wsgi (Apache2)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM