我的休息服務位于http://127.0.0.1:5000,但是當我啟動它時,它給了我 404:Not FoundThe requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.這是為什么?我希望我的服務器顯示一些狀態(tài)消息,例如“服務就緒”。當我按“http://127.0.0.1:5000/parser/tengrinews”并按回車鍵時,我將使用的實際功能是可訪問且有效的,它會輸出我在 Flask 應用程序的功能中編碼的消息:[ "parsing this website :", "tengrinews"]主要代碼:from flask import Flaskimport requestsfrom datetime import datetimefrom flask import jsonifyapp = Flask(__name__)#this is my std method i can't see@app.route("/http://127.0.0.1:5000/", methods = ['GET'])def main(): return jsonify('service is ready')@app.route("/parser/<string:website>", methods = ['GET'])def parse(website): return jsonify("parsing this website :", website )if __name__ == "__main__": app.run(debug=True)
1 回答

天涯盡頭無女友
TA貢獻1831條經(jīng)驗 獲得超9個贊
更改此行 -
@app.route("/http://127.0.0.1:5000/", methods = ['GET'])
到@app.route("/", methods = ['GET'])
。
因為您只需指定將要使用的擴展 URL。裝飾@app.route
者為我們處理剩下的事情
注意*(不要這樣做。僅供娛樂)-
如果您想繼續(xù)使用,@app.route("/http://127.0.0.1:5000/", methods = ['GET'])
請使用 url - 訪問端點http://localhost:5000/http://127.0.0.1:5000/
。你會得到這樣的回應"service is ready"
添加回答
舉報
0/150
提交
取消