栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

ImportError:没有名为django.core.wsgi的模块Apache + VirtualEnv + AWS + WSGI

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

ImportError:没有名为django.core.wsgi的模块Apache + VirtualEnv + AWS + WSGI

我知道这是一个旧线程,但是我碰到了同样的问题,我不认为这是由缺少软件包引起的。由于Django核心发行版已经包含正确的wsgi处理程序。

这里的问题是,执行wsgi.py时,它会丢失你virtualenv中的站点软件包。(如果你已经激活了virtualenv,并完成了pip install django的安装,那么一切都很好。你已经有了必要的django软件包)。

就我而言,我修复了修改Path / to / Project / Project / wsgi.py文件中sys.path的问题。

你必须将项目目录和virtualenv站点程序包附加到sys.path列表中。这是我的项目中包含的wsgi.py文件(谈论用django-admin.py start-project创建的wsgi.py)…为了使其与Apache一起使用,我必须对其进行修改。

# =====================# wsgi.py file begin import os, sys# add the hellodjango project path into the sys.pathsys.path.append('<PATH_TO_MY_DJANGO_PROJECT>/hellodjango')# add the virtualenv site-packages path to the sys.pathsys.path.append('<PATH_TO_VIRTUALENV>/Lib/site-packages')# poiting to the project settingsos.environ.setdefault("DJANGO_SETTINGS_MODULE", "hellodjango.settings")from django.core.wsgi import get_wsgi_applicationapplication = get_wsgi_application()# wsgi.py file end# ===================

确保:

  1. 你将mod_wsgi添加到Apache模块目录dir mod_wsgi必须针对你拥有的OS,Apache和Python版本进行编译
  2. 在你的httpd.conf中添加了load module命令以加载mod_wsgi模块LoadModule wsgi_module modules / mod_wsgi.so
  3. 你在httpd.conf或你在httpd.conf中包含的任何conf中配置的Django特定细节

基于文档,如何将Django与Apache和mod_wsgi结合使用

WSGIscriptAlias / <PATH_TO_PROJECT>/hellodjango/hellodjango/wsgi.pyWSGIPythonPath <PATH_TO_PROJECT>:<PATH_TO_VIRTUALENV>/Lib/site-packages<Directory <PATH_TO_PROJECT>/hellodjango/hellodjango>   <Files wsgi.py>    Order deny,allow    Require all granted  </Files></Directory>

希望这可以帮助。它为我工作。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/407793.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号