簡體   English   中英

Flask不適用於調試模式

[英]Flask don't work with debug mode

我在werkzeug我的小包裝時遇到了奇怪的werkzeug問題。

問題 :當我嘗試以調試模式運行應用程序時,為了運行我的應用程序,我使用命令python3 -m my_app --start

我收到錯誤 ModuleNotFoundError: No module named '__main__.helpers'; '__main__' is not a package ModuleNotFoundError: No module named '__main__.helpers'; '__main__' is not a package

文件很簡單

app.py

class Application:
    """Main class"""
    def __init__(self):
        self.reader = ApplicationReader()
        self.app = Flask(self.reader.name)

    def __start_server(self):
        """Custom method, for starting flask application"""
        self.app.run(debug=True)

    def run(self):
        """Run the server"""
        return self.__start_server()


# Instance of Application class
application = Application()


def start_app():
    """Start the mock server
    """
    return application.run()

__main__.py

def cli(run, init, start):
    if run:
        print('Your API is running...')
    if init:
        create_init_file()
    if start:
        start_app()

if __name__ == '__main__':
    cli()

似乎無法修復該錯誤, GitHub問題

那么,也許有人對此案有解決方案? 謝謝。

我為start_app函數創建了另一個文件,因為我發現在調試模式下無法實現導入。

start_app.pyapp.py旁邊)

import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__)))
print("sys.path", sys.path) # use this to check if the last entry has the right folder
from app import start_app
start_app()

現在,您可以在調試模式下使用python -m start_app.py運行它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM