简体   繁体   中英

Python AppEngine - How to pass query strings in app.yaml

I'm trying to set different folders according to mobile platforms, but I can't figure it out how to do it.

Here's some code:

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

this works fine but when I set the query string like this:

- 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

It does not!

I basically want to send different resources according to each platform, is this possible?

Thanks :)

ps: Similar question that says "no" to what I want to achieve Define query param in app.yaml in Google Appengine

As the answer to the question you referenced, query parameters are ignored when routing via app.yaml . But it is possible to offer different resources according to each platform, only using other mechanisms.

One approach could be by encoding the platform in the URL, but not as a query parameter, for example /winners/android , handled via this app.yaml routing:

- 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

Which would serve a file stored as static_files/android/winners.json

More details in Static file pattern handlers .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM