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

标签 python google-app-engine yaml

我正在尝试根据移动平台设置不同的文件夹,但我不知道该怎么做。

这是一些代码:

应用程序.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

最佳答案

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

一种方法是在 URL 中对平台进行编码,但不作为查询参数,例如 /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 .

关于Python AppEngine - 如何在 app.yaml 中传递查询字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36721569/

相关文章:

python - "ImportError: No module named pwd"但它存在

c# - 访问 Unity 层的名称

amazon-web-services - 使用 cloudfront 的 s3 上的访问被拒绝错误

Azure Pipeline - 使用 YAML 将文件从一个存储库复制到另一个存储库

python - 从 python sys.path 中永久删除一些东西

python 幽灵脚本 : RuntimeError: Can not find Ghostscript library (libgs)

python - Pandas 查找并插入缺失值

java - 无法使用 Google App Engine (GAE) 连接到 Google Cloud Messaging (GCM) 服务器

python - 如何根据多列过滤 Pandas 数据集?

python - 如何从非浏览器客户端使用用户 API 登录 GAE 应用程序?