0
我正在通過RealPython工作,我遇到燒瓶動態路線的問題。燒瓶動態路線不工作 - 真正的Python
一切似乎工作,直到動態路線。現在,如果我嘗試輸入「搜索查詢」(即localhost:5000/test/hi),則找不到該頁面。 localhost:5000仍然正常。
# ---- Flask Hello World ---- #
# import the Flask class from the flask module
from flask import Flask
# create the application object
app = Flask(__name__)
# use decorators to link the function to a url
@app.route("/")
@app.route("/hello")
# define the view using a function, which returns a string
def hello_world():
return "Hello, World!"
# start the development server using the run() method
if __name__ == "__main__":
app.run()
# dynamic route
@app.route("/test/<search_query>")
def search(search_query):
return search_query
我看不到使用RealPython的其他人有相同的代碼的問題,所以我不知道我做錯了什麼。
那你有沒有把動態路由後'app.run()'? –
那麼,你的代碼可以在這裏很好用。 'localhost:5000/test/hi','localhost:5000'或'localhost:5000/hello'會返回正確的字符串,我沒有收到404錯誤。 –
它重新啓動我的電腦後工作。 –