mod_python + flask框架如何调适?

发布于 2022-08-25 11:02:14 字数 3057 浏览 23 评论 0

在win下使用xampp,并且安装了mod_python,然后使用flask给的例子,使用以下方法调用函数。

def handler(req):
    req.content_type='text/plain'
    init_db()
    app.run()
    return apache.OK

例子为:https://github.com/mitsuhiko/flask/tree/master/examples/flaskr/

apache的http.conf加入了以下代码

<Directory "D:/xampp/htdocs/python/flaskr">
AllowOverride FileInfo
SetHandler python-program
AddHandler mod_python .py
PythonAutoReload On
PythonHandler flaskr
PythonDebug On

然后访问localhost/python/flaskr报错

MOD_PYTHON ERROR

ProcessId: 9880 Interpreter: 'localhost'

ServerName: 'localhost' DocumentRoot: 'D:/xampp/htdocs'

URI: '/python/flaskr/' Location: None Directory: 'D:/xampp/htdocs/python/flaskr/' Filename: 'D:/xampp/htdocs/python/flaskr/' PathInfo: ''

Phase: 'PythonHandler' Handler: 'flaskr'

Traceback (most recent call last):

File "C:\Python27\lib\site-packages\modpython\importer.py", line 1537, in HandlerDispatch default=defaulthandler, arg=req, silent=hlist.silent)

File "C:\Python27\lib\site-packages\modpython\importer.py", line 1202, in _processtarget module = importmodule(modulename, path=path)

File "C:\Python27\lib\site-packages\modpython\importer.py", line 296, in importmodule log, import_path)

File "C:\Python27\lib\site-packages\modpython\importer.py", line 680, in importmodule execfile(file, module.dict)

File "D:\xampp\htdocs\python\flaskr\flaskr.py", line 35, inapp.config.from_object(name)

File "C:\Python27\lib\site-packages\flask\config.py", line 162, in fromobject obj = importstring(obj)

File "C:\Python27\lib\site-packages\werkzeug-0.8.3-py2.7.egg\werkzeug\utils.py", line 411, in importstring return import(importname)

ImportStringError: importstring() failed for 'mp_d645bbbdbf6c8b566289f00aa0ab7147'. Possible reasons are:

  • missing init.py in a package;
  • package or module path not included in sys.path;
  • duplicated package or module name taking precedence in sys.path;
  • missing module, class, function or variable;

Debugged import:

  • 'mpd645bbbdbf6c8b566289f00aa0ab7147' not found.

Original exception:

ImportError: No module named mpd645bbbdbf6c8b566289f00aa0ab7147

MODULE CACHE DETAILS

Accessed: Tue May 07 18:04:34 2013 Generation: 0

mpd645bbbdbf6c8b566289f00aa0ab7147 { FileName: 'D:\xampp\htdocs\python\flaskr\flaskr.py' Instance: 1 [IMPORT] Generation: 0 [ERROR] Modified: Tue May 07 16:28:18 2013 }

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文