我在使用Flask进行URL路由时遇到了问题,似乎路由没有按照预期工作。
Under
project/src/views.py
, I have the following sample routesfrom flask import (Flask,request,jsonify,Blueprint) my_view = Blueprint('my_view', __name__) @my_view.route('/',methods=("GET",)) @my_view.route('/index',methods=("GET",)) def index(): .... <return response code here> @my_view.route("/key/<inp1>/<inp2>", methods=("POST","GET")) def getKey(inp1=None, inp2=None): .... <return response code here>
Now, under
project/src/app.py
, I have the following codefrom ../src.views import my_view my_app = Flask("myappname") my_app.register_blueprint(my_view) my_app.run(debug=True,host=APP_IP,port=APP_PORT)
http://ip:port/index
或 http://ip:port/key...
时,它会返回 404 错误,并显示消息“服务器上未找到请求的 URL。如果您手动输入了 URL,请检查拼写并重试。” 我认为这些路由不起作用。