简体   繁体   English

部署Django(mod_python)

[英]Deploy Django (mod_python)

FIXED 固定

my setup: 我的设置:

apache + mod_python VPS with CentOS django 1.2.5 使用CentOS Django 1.2.5的apache + mod_python VPS

I have uploaded my files to /mysite 我已将文件上传到/ mysite

and set httpd.conf as followed: 并按如下所示设置httpd.conf:

< VirtualHost *:80 >

    DocumentRoot /var/www/html/domain
    ServerName www.domain.com
    ServerAlias domain.com

    #django...
    <Location "/mysite">
        SetHandler python-program
        PythonHandler django.core.handlers.modpython
        SetEnv DJANGO_SETTINGS_MODULE mysite.settings
        PythonOption django.root /mysite
        PythonDebug On
        PythonPath "['/var/www/html/domain/mysite'] + sys.path"
    </Location>

    CustomLog logs/access_log cplus

< /VirtualHost >

I get this error: 我收到此错误:

Mod_python error: "PythonHandler django.core.handlers.modpython"

Traceback (most recent call last):

  File "/usr/lib64/python2.4/site-packages/mod_python/apache.py", line 299, in HandlerDispatch
    result = object(req)

  File "/usr/lib/python2.4/site-packages/django/core/handlers/modpython.py", line 228, in handler
    return ModPythonHandler()(req)

  File "/usr/lib/python2.4/site-packages/django/core/handlers/modpython.py", line 191, in __call__
    self.load_middleware()

  File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py", line 33, in load_middleware
    for middleware_path in settings.MIDDLEWARE_CLASSES:

  File "/usr/lib/python2.4/site-packages/django/utils/functional.py", line 276, in __getattr__
    self._setup()

  File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", line 40, in _setup
    self._wrapped = Settings(settings_module)

  File "/usr/lib/python2.4/site-packages/django/conf/__init__.py", line 75, in __init__
    raise ImportError("Could not import settings '%s' (Is it on sys.path? Does it have syntax errors?): %s" % (self.SETTINGS_MODULE, e))

ImportError: Could not import settings 'mysite.settings' (Is it on sys.path? Does it have syntax errors?): No module named mysite.settings

You are defining the handler for www.domain.com/mysite 您正在为www.domain.com/mysite定义处理程序

Have you tried to access that URL? 您是否尝试访问该URL?

If you want www.domain.com showing your mysite app use 如果您希望www.domain.com显示您的mysite应用程序使用情况

<Location "/">
    ...
    # remove django.root /mysite
</Location>

EDIT 编辑

To your second problem: mysite.settings is not in your python path. 第二个问题: mysite.settings不在您的python路径中。 Either add '/var/www/html/domain' to the PythonPath list, maybe just using settings as the DJANGO_SETTINGS_MODULE also solves the problem. 将“ / var / www / html / domain”添加到PythonPath列表中,也许只是使用settings因为DJANGO_SETTINGS_MODULE也可以解决该问题。

Hope that helps! 希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM