我在 heroku 上托管的 Angular + Flask 中编写了一个应用程序。我一直在寻找使用 html5mode 来使用 myapp.co/register
进行 oauth。 html5mode 的问题是,如果有人刷新页面或点击非root 的链接,服务器需要重写url。我尝试使用 this片段来捕获所有这些,但它不起作用。
@app.route("/", defaults={"path": ""})
@app.route("/<path:path>")
def index(path):
print path
return make_response(open(app.static_folder + "index.html").read())
输出404
* Restarting with reloader
127.0.0.1 - - [23/Jan/2014 13:41:48] "GET /ass HTTP/1.1" 404 -
应用程序获得服务器 index.html 和/api/v1/的根目录,这是 RESTful api
最佳答案
你需要使用比你拥有的更多的东西:
@app.route("/", defaults={"path": ""})
@app.route("/<string:path>") <--- this is missing
@app.route("/<path:path>")
def index(path):
print path
return make_response(open(app.static_folder + "index.html").read())
所以:
@app.route("/<string:path>")
不见了。它捕获字符串变量(而不是路径),因此在您的情况下,当您尝试点击 http://localhost:5000/ass 时,只需从您的示例中获取 ass
.
关于javascript - 捕获 flask 应用程序中的所有路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21310147/