0

我在使用 mod_wsgi 在 Apache 中部署我的构建项目(Django)时遇到了一些问题。

我的文件夹结构:

t/
  bootstrap.py
  setup.py
  bin/
     buildout
     django
     django.wsgi
     .....
  eggs/
       raven-3.1.13-py2.7.egg
       ..........
  parts
  project
  develop-eggs
  src/
     some files
  myapp/

    files
    settings.py
    apicontainer/
        ....

应用程序配置文件:

<VirtualHost *:80>
        DocumentRoot /home/.../tests/website
         ServerName testapp.com
        <Directory /home/.../tests/website>
            Order allow,deny
            Allow from all
        </Directory>

        Alias /website/ /home/.../tests/website/

        WSGIDaemonProcess testapp.com processes=2 threads=15 display-name=%{GROUP}
        WSGIProcessGroup testapp.com
        # ........ pointing to buildout's django.wsgi ..........
        WSGIScriptAlias / /home/.../tests/t/bin/django.wsgi
        WSGIPassAuthorization On

        ErrorLog ${APACHE_LOG_DIR}/error.log

        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn    
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

./bin/django.wsgi

#!/usr/bin/python


import sys
sys.path[0:0] = [
  '/home/.../tests/t/eggs/raven-3.1.13-py2.7.egg',
  '/usr/lib/python2.7/dist-packages',
   ...........
   ...........

  '/home/.../tests/t/eggs/djangorecipe-1.5-py2.7.egg',
  '/home/.../tests/t/eggs/zc.recipe.egg-2.0.0a3-py2.7.egg',
  '/home/.../tests/t',
  ]

import djangorecipe.wsgi

application = djangorecipe.wsgi.main('testproj.settings', logfile='')

构建.cfg

[buildout]
parts = python
        django

develop = .
eggs = raven
       .....
       .....

[python]
recipe = zc.recipe.egg
interpreter = python
eggs = ${buildout:eggs}

[django]
recipe = djangorecipe
wsgi = true
project = testproj
settings = settings
eggs = ${buildout:eggs}

我得到的apache错误日志是:

[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] mod_wsgi (pid=9772): Exception occurred processing WSGI script '/home/.../tests/t/bin/django.wsgi'.
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1]   File "/usr/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 272, in __call__
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1]     response = self.get_response(request)
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1]   File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line 153, in get_response
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1]     response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1]   File "/usr/lib/python2.7/dist-packages/django/core/handlers/base.py", line 218, in handle_uncaught_exception
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1]     return callback(request, **param_dict)
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1]   File "/usr/lib/python2.7/dist-packages/django/utils/decorators.py", line 93, in _wrapped_view
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1]     response = view_func(request, *args, **kwargs)
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1]   File "/usr/lib/python2.7/dist-packages/django/views/defaults.py", line 30, in server_error
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1]     t = loader.get_template(template_name) # You need to create a 500.html template.
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1]   File "/usr/lib/python2.7/dist-packages/django/template/loader.py", line 157, in get_template
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1]     template, origin = find_template(template_name)
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1]   File "/usr/lib/python2.7/dist-packages/django/template/loader.py", line 138, in find_template
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1]     raise TemplateDoesNotExist(name)
[Thu Feb 21 06:19:09 2013] [error] [client 127.0.0.1] TemplateDoesNotExist: 500.html

我将 prmission(777) 授予 bin 文件夹。

为了测试 wsgi 的工作,我将 django.wsgi 更改如下,然后将其恢复为旧版本。

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!'

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

它给了我结果 Hello World!。

你能帮我找出问题吗?

4

1 回答 1

0

您收到 TemplateDoesNotExist 错误,这意味着您缺少“500.html”模板(请参阅文档)。

我建议在您的文件中设置DEBUG为(请参阅文档)。这将导致 django 使用内置的调试模板(而不是缺少的 '500.html')。调试模板将为您提供更多信息以使用...Truesettings.py

于 2013-02-22T10:20:12.723 回答