Python AppEngine - 如何在app.yaml中传递查询字符串

时间:2016-04-19 14:36:57

标签: python google-app-engine yaml

我正在尝试根据移动平台设置不同的文件夹,但我无法弄明白该怎么做。

以下是一些代码:

的app.yaml

- url: /winners
  secure: always
  static_files: static_files/winners.json
  upload: static_files/winners.json
  http_headers:
    Content-Type: application/json; charset=latin-1

这工作正常,但是当我像这样设置查询字符串时:

- url: /winners?platform=android
  secure: always
  static_files: static_files/winners.json
  upload: static_files/winners.json
  http_headers:
    Content-Type: application/json; charset=latin-1

它没有!

我基本上想根据每个平台发送不同的资源,这可能吗?

谢谢:)

ps:类似的问题,对我想达到的目标说“不”Define query param in app.yaml in Google Appengine

1 个答案:

答案 0 :(得分:3)

作为您引用的问题的答案,在通过app.yaml进行路由时会忽略查询参数。但是可以根据每个平台提供不同的资源,只使用其他机制。

一种方法可以是在网址中对平台进行编码,但不能作为查询参数,例如/winners/android,通过此app.yaml路由处理:

- url: /winners/(.*)$
  secure: always
  static_files: static_files/\1/winners.json
  upload: static_files/\1/winners.json
  http_headers:
    Content-Type: application/json; charset=latin-1

将提供存储为static_files/android/winners.json

的文件

Static file pattern handlers中的更多详情。