以下是myapplication目录的结构:
|`-- mymodules
|-- config.py
|-- __init__.py
|-- views.py
|-- mod_stock
| |-- __init__.py
| |-- static
| |-- templates
| `-- views.py
以下是mod_stock / views.py中的代码:
from flask import Blueprint
stockBlueprint = Blueprint('stock',
__name__,
template_folder = 'templates',
static_folder = 'static')
@stockBlueprint.route("/getStock",methods=['GET'])
def getStock():
return "stock value"
以下是mod_stock / init .py:
中的代码from . import views
mymodules / views.py中的代码:
from mymodules import mainBlueprint
@mainBlueprint.route("/")
def gethomepage():
return "homepage"
mymodules中的代码/ init .py
from flask import Blueprint, Flask
from config import Config
application = Flask(__name__)
application.config.from_object(Config)
mainBlueprint = Blueprint('main',__name__)
from views import *
from .mod_stock.views import stockBlueprint
application.register_blueprint(mainBlueprint)
application.register_blueprint(stockBlueprint)
我可以看到路由已在application.url_map中注册。但是,当我卷曲localhost:5000或卷曲localhost:5000 / getStock时,我收到404错误。那么我该怎么做才能解决这个问题呢?
在myapplication下/我是main.py,它从mymodules导入应用程序并运行它。
编辑:以下是代码:
from mymodules import application
if __name__ == '__main__':
application.run(host="0.0.0.0", port=5000, use_reloader=False, debug=True)