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错误。 –
它重新启动我的电脑后工作。 –