使用 mod_python 在 Django 中运行我的应用程序时出错

发布于 2024-09-18 21:14:53 字数 2598 浏览 6 评论 0原文

我有win32,python2.5,django1.2,apache2.2和mod_python3.3.1

我已经正确安装了mod_python。 现在我的应用程序名称是 myapp.setting,路径是 c:\myapp.setting。在 myapp.settings 中,我的文件是 myapp.settings\url.py,settings.py 等。

现在在 apache httpd.conf 文件中,我进行了以下更改:-

<Location "/mysite">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE myapp.settings
    PythonDebug On
    PythonPath "['/'] + sys.path"
</Location>

并且我在 PythonPath 中尝试了许多更改。但是当我输入 http://localhost/mysite 时,错误如下:-

MOD_PYTHON 错误

ProcessId:      1384
Interpreter:    '192.168.1.166'

ServerName:     '192.168.1.166'
DocumentRoot:   'C:/Program Files/Apache Software Foundation/Apache2.2/htdocs'

URI:            '/mysite'
Location:       '/mysite'
Directory:      None
Filename:       'C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/mysite'
PathInfo:       ''

Phase:          'PythonHandler'
Handler:        'django.core.handlers.modpython'

Traceback (most recent call last):

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1229, in _process_target
    result = _execute_target(config, req, object, arg)

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1128, in _execute_target
    result = object(arg)

  File "C:\Python25\Lib\site-packages\django\core\handlers\modpython.py", line 228, in handler
    return ModPythonHandler()(req)

  File "C:\Python25\Lib\site-packages\django\core\handlers\modpython.py", line 191, in __call__
    self.load_middleware()

  File "C:\Python25\Lib\site-packages\django\core\handlers\base.py", line 33, in load_middleware
    for middleware_path in settings.MIDDLEWARE_CLASSES:

  File "C:\Python25\Lib\site-packages\django\utils\functional.py", line 276, in __getattr__
    self._setup()

  File "C:\Python25\Lib\site-packages\django\conf\__init__.py", line 40, in _setup
    self._wrapped = Settings(settings_module)

  File "C:\Python25\Lib\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 'myapp.settings' (Is it on sys.path? Does it have syntax errors?): No module named myapp.settings

请帮助我,我是新来的姜戈...

I have win32,python2.5,django1.2, apache2.2, and mod_python3.3.1

I have installed properly mod_python.
Now my application name is myapp.setting which path is c:\myapp.setting. In myapp.settings my file is myapp.settings\url.py,settings.py etc.

now in apache httpd.conf file I have changes following:-

<Location "/mysite">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE myapp.settings
    PythonDebug On
    PythonPath "['/'] + sys.path"
</Location>

and I have tried many changes in PythonPath. but when i typed http://localhost/mysite the error is following:-

MOD_PYTHON ERROR

ProcessId:      1384
Interpreter:    '192.168.1.166'

ServerName:     '192.168.1.166'
DocumentRoot:   'C:/Program Files/Apache Software Foundation/Apache2.2/htdocs'

URI:            '/mysite'
Location:       '/mysite'
Directory:      None
Filename:       'C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/mysite'
PathInfo:       ''

Phase:          'PythonHandler'
Handler:        'django.core.handlers.modpython'

Traceback (most recent call last):

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1537, in HandlerDispatch
    default=default_handler, arg=req, silent=hlist.silent)

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1229, in _process_target
    result = _execute_target(config, req, object, arg)

  File "C:\Python25\Lib\site-packages\mod_python\importer.py", line 1128, in _execute_target
    result = object(arg)

  File "C:\Python25\Lib\site-packages\django\core\handlers\modpython.py", line 228, in handler
    return ModPythonHandler()(req)

  File "C:\Python25\Lib\site-packages\django\core\handlers\modpython.py", line 191, in __call__
    self.load_middleware()

  File "C:\Python25\Lib\site-packages\django\core\handlers\base.py", line 33, in load_middleware
    for middleware_path in settings.MIDDLEWARE_CLASSES:

  File "C:\Python25\Lib\site-packages\django\utils\functional.py", line 276, in __getattr__
    self._setup()

  File "C:\Python25\Lib\site-packages\django\conf\__init__.py", line 40, in _setup
    self._wrapped = Settings(settings_module)

  File "C:\Python25\Lib\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 'myapp.settings' (Is it on sys.path? Does it have syntax errors?): No module named myapp.settings

Please help me I am new in Django...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风渺 2024-09-25 21:14:53

正如 rebus 在他的评论中所说,将您的项目称为“myapp.settings”是无意义的。它既不是应用程序(它是网站的组件),也不是设置文件。称其为合理的名称 - 如果您确实想不出任何东西,请将其称为“我的网站”。

但最后,您不应该使用 mod_python。请改用 mod_wsgi。

As rebus says in his comment, it's nonsense to call your project 'myapp.settings'. It's neither an app (which is a component of a site), nor is it a settings file. Call it something sensible - if you really can't think of anything, call it 'mysite'.

Finally, however, you should not be using mod_python. Use mod_wsgi instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文