【问题标题】:Issue in deployment zc.buildout with apache使用 apache 部署 zc.buildout 时出现问题
【发布时间】:2013-02-22 09:24:34
【问题描述】:

我在使用 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='')

buildout.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

我授予 bin 文件夹权限(777)。

为了测试 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!。

你能帮我找出问题吗?

【问题讨论】:

  • Template does not exist: 500.html 有帮助吗?你的TEMPLATE_DIRS 是什么样的?
  • 一开始我没有在djangorecipe中给project = testproj,现在我加了。现在我得到了 404page.ie 它开始以某种方式工作。 Djano 现在在项目的生成目录中查找 url、设置、模板。这是默认行为吗?它不在我创建的 src 目录中。我可以改变这种行为吗?
  • djangorecipe 中“项目”的重要性是什么

标签: python django apache2 mod-wsgi buildout


【解决方案1】:

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

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

【讨论】:

  • 恐怕我没有使用过 buildout,所以我在这里猜测了一下。听起来你的 python 路径有问题。也许尝试将您的应用显式添加到 buildout.cfg 中的 extra_paths。
  • DEBUG = True in my settings.py
  • 现在它以某种方式工作。Django 查找在生成的项目文件夹中指定的 url(在 djangorecipe 中指定)。 Djngo 不会在我的 src 文件夹中查找资源。我怎样才能改变它?
猜你喜欢
  • 2012-04-13
  • 2021-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-20
  • 1970-01-01
  • 1970-01-01
  • 2011-07-21
相关资源
最近更新 更多