当部署到apache服务器时,django项目导入问题与mod_wsgi

时间:2011-12-08 13:47:13

标签: django apache2 mod-wsgi


将我的django网络应用程序解除本地apache服务器,在开发服务器上工作时出现问题。我的项目名称是'DjangoApis' 项目结构:home / ji / Desktop / testcloud / DjangoApis /

__init__.py
  django.wsgi
  settings.py
  manage.py
  urls.py 
  mywebapp
       --> __init__.py
       --> static
       --> templates
       --> urls.py
       --> views.py
  myapis ( create it as a project itself)
       --> __init__.py
       --> manage.py
       --->....

settings.py:

INSTALLED_APPS = (        
    'DjangoApis.mywebapp',
    'DjangoApis.myapis',
)

django.wsgi:

**

import os
import sys
path = '/home/ji/Desktop/testcloud.aws'
if path not in sys.path:
    sys.path.append(path)   
os.environ['DJANGO_SETTINGS_MODULE'] = 'DjangoApis.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

**

项目文件夹(DjangoApis)中的

urls.py

urlpatterns = patterns('',   

    url(r'^admin/', include(admin.site.urls)),
)
urlpatterns = patterns('',
  (r'^api/', include('DjangoApis.myapis.url')),
  (r'^', include('DjangoApis.mywebapp.urls')),      
)

的/ etc / apache2的/启用的站点 -

 VirtualHost *:80
        ServerName test.webapp
        DocumentRoot /home/ji/Desktop/testcloud/DjangoApis

        <Directory /home/ji/Desktop/testcloud/DjangoApis>
            Order allow,deny
            Allow from all
        </Directory> 
        WSGIDaemonProcess test.webapp processes=2 threads=15 display-name=%{GROUP}
        WSGIProcessGroup test.webapp 
        WSGIScriptAlias / /home/ji/Desktop/testcloud/DjangoApis/django.wsgi

    /VirtualHost

当我在浏览器中运行&lt;我收到了内部服务器错误     错误日志:

tail /var/log/apache2/error.log
[Thu Dec 08 06:26:32 2011] [error] [client 127.0.0.1]     default_translation = _fetch(settings.LANGUAGE_CODE)
[Thu Dec 08 06:26:32 2011] [error] [client 127.0.0.1]   File "/usr/lib/pymodules/python2.7/django/utils/translation/trans_real.py", line 162, in _fetch
[Thu Dec 08 06:26:32 2011] [error] [client 127.0.0.1]     app = import_module(appname)
[Thu Dec 08 06:26:32 2011] [error] [client 127.0.0.1]   File "/usr/lib/pymodules/python2.7/django/utils/importlib.py", line 35, in import_module
[Thu Dec 08 06:26:32 2011] [error] [client 127.0.0.1]     __import__(name)
  

[Thu Dec 08 06:26:32 2011] [错误] [客户端127.0.0.1]   TemplateSyntaxError:渲染时捕获ImportError:无模块   名为myapis

[Thu Dec 08 17:56:46 2011] [notice] SIGUSR1 received.  Doing graceful restart
[Thu Dec 08 17:56:46 2011] [warn] mod_wsgi: Compiled for Python/2.7.2rc1.
[Thu Dec 08 17:56:46 2011] [warn] mod_wsgi: Runtime using Python/2.7.2+.
[Thu Dec 08 17:56:46 2011] [notice] Apache/2.2.20 (Ubuntu) mod_wsgi/3.3 Python/2.7.2+ configured -- resuming normal operations

注意:我使用的是django活塞。请帮我纠正这个问题,提前谢谢。

1 个答案:

答案 0 :(得分:0)

添加:

sys.path.append('/home/ji/Desktop/testcloud.aws/DjangoApis')

您需要同时添加父目录和项目目录:

http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango