javascript - 捕获 flask 应用程序中的所有路径

标签 javascript python html angularjs flask

我在 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/

相关文章:

javascript - 根据函数结果更改数据百分比属性?

javascript - Chrome 控制台对象

javascript - AngularJS - Controller 可见性

python - 无法将输出转换为列表

Python:为什么会出现这个错误?

android - 谷歌文档中有没有官方的方法来启动 html5 android 应用程序?

html - 糟糕的网站响应

javascript - 如何修改对象 getter 返回的私有(private)变量?

javascript - 用链接替换标签,它只替换字符串中的最后一个词

python - PyGame 中的闪烁文本