Django:从开发服务器转移到部署(Apache+mod_wsgi)
我正在 Django 上开发应用程序,并准备移动到部署服务器。我能够在 apache 上运行一个新的 django 项目(我可以看到欢迎页面)。 但是,当我将原始项目的文件复制到 apache 项目目录时,我开始收到错误。这是来自 apache/error.log 的示例。
[Wed Jan 26 19:22:08 2011] [error] [client 127.0.0.1] TemplateSyntaxError: Caught ImportError while rendering: No module named charts
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] mod_wsgi (pid=4670): Exception occurred processing WSGI script '/srv/www/enpass/apache/django.wsgi'.
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] Traceback (most recent call last):
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 241, in __call__
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] response = self.get_response(request)
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 141, in get_response
我的 django.wsgi 文件看起来
import os
import sys
path = '/srv/www'
if path not in sys.path:
sys.path.insert(0, '/srv/www')
os.environ['DJANGO_SETTINGS_MODULE'] = 'enpass.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
我已经更改了文件中的所有路径以适应新的目录结构,所以我很确定这不是问题。 FIY,我按照本教程中给出的步骤 http://blog.stannard.net.au/2010/12/11/installing-django-with-apache-and-mod_wsgi-on-ubuntu-10-04/
I'm developing application on Django, and ready to move to deployment server. I'm able to run a new django project on apache(I can see the welcome page).
However, when I copy my original project's files to apache project directory, I start getting errors. Here is a sample from apache/error.log.
[Wed Jan 26 19:22:08 2011] [error] [client 127.0.0.1] TemplateSyntaxError: Caught ImportError while rendering: No module named charts
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] mod_wsgi (pid=4670): Exception occurred processing WSGI script '/srv/www/enpass/apache/django.wsgi'.
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] Traceback (most recent call last):
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/wsgi.py", line 241, in __call__
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] response = self.get_response(request)
[Wed Jan 26 19:22:36 2011] [error] [client 127.0.0.1] File "/usr/local/lib/python2.6/dist-packages/django/core/handlers/base.py", line 141, in get_response
My django.wsgi file looks like
import os
import sys
path = '/srv/www'
if path not in sys.path:
sys.path.insert(0, '/srv/www')
os.environ['DJANGO_SETTINGS_MODULE'] = 'enpass.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
I've changed all the paths in files to suit the new directory structure, so I'm pretty sure thats not the problem. FIY, I followed the steps given in this tutorial http://blog.stannard.net.au/2010/12/11/installing-django-with-apache-and-mod_wsgi-on-ubuntu-10-04/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我自己想出来了。我们需要将项目目录路径添加到sys.path中。以下代码解决了 django.wsgi 中的问题
I figured it out myself. We need to add the project directory path to sys.path. The following code solved the problem in django.wsgi
看起来您缺少图表模块。
安装 pip
list 包
在开发计算机上执行相同的操作并查找图表模块,然后使用以下命令将其安装在生产服务器上
Looks like you are missing the charts module..
install pip
list packages
do the same on the development machine and look for a chart module, then install it on the production server with