带mod_wsgi的烧瓶 - 无法调用我的模块

时间:2016-12-29 14:32:05

标签: python flask undefined global mod-wsgi

我已将使用flask和python2.7运行的应用程序从独立解决方案更改为使用apache和mod_wsgi的烧瓶。

我的Flask应用程序(app.py)包含一些类,这些类位于我的app dir(../)下面的目录中。

这是我的app.wsgi:


    #!/usr/bin/python
    import sys
    import logging
    logging.basicConfig(stream=sys.stderr)
    sys.stdout = sys.stderr


    project_home = '/opt/appdir/Application/myapp'
    project_web  = '/opt/appdir/Application/myapp/web'


    if project_home not in sys.path:
        sys.path = [project_home] + sys.path

    if project_web not in sys.path:
        sys.path = [project_web] + sys.path

    from app import app
    application = app
    

在配置mod_wsgi之前,app.py中的主要调用看起来像是:


    # Main
    if __name__ == '__main__' :
        from os import sys, path
        sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))
        from logger import Logger
        from main import Main
        from configReader import ConfigReader
        print "Calling flask"
        from threadhandler import ThreadHandler
        ca = ConfigReader()
        app.run(host="0.0.0.0", threaded=True)

我完全能够在下面的目录中加载我的课程。 用mod_wsgi运行应用程序后,我收到以下错误:  全球名称\' Main \'未定义

那么我如何更改我的应用程序,这将在这里工作:


    @app.route("/")
    def test():
       main = Main("test")
       return main.responseMessage()
 

感谢您的回复。

祝你好运 Joern

1 个答案:

答案 0 :(得分:0)

感谢您回复我的要求。没有mod_wsgi的主函数调用是正确的答案。我没有在wsgi文件中实现我需要的模块, 但在烧瓶应用程序之上。这项工作对我来说很好;)

谢谢你们,祝大家新年快乐。

祝福 Joern

相关问题