django+mod_wsgi on virtualenv not working

▼魔方 西西 提交于 2019-12-04 04:38:33

I'd recommend that you look at the docs for using Virtualenv with mod_wsgi. They offer a few alternative approaches for hooking into your virtualenv which might work better for you.

You need to add the directory that is two up from your wsgi file, so instead of:

root_path = os.path.abspath(os.path.dirname(__file__) + '../')

you should have

root_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../', '../'))

...as your wsgi file is in a directory called apache, under your project folder.

If you're using a virtualenv, you'll need to activate it within the WSGI script to set the paths up correctly.

root_path = os.path.abspath(os.path.dirname(__file__) + '../')
activate_this = os.path.join(root_path, "bin/activate_this.py")
execfile(activate_this, dict(__file__=activate_this))
Carl Meyer

Do you have an __init__.py file in your "kcdf" directory? Without that your settings file cannot be imported.

Also, you should be calling site.addsitedir() on the virtualenv's site-packages directory, if you expect to be able to import stuff from the virtualenv. See the mod_wsgi docs for details. Though if it can't even import your settings, I don't think this is your current problem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!