akonsu
akonsu

Reputation: 29538

how to get static URL inside GAE app

my app.yaml:

handlers:
  - url: /static
    static_dir: static

  - url: /.*
    script: main.app

is there a way, inside my webapp2 code, to get the absolute URL of the /static route?

Upvotes: 0

Views: 276

Answers (2)

voscausa
voscausa

Reputation: 11706

When you define routes in your application you can compute an uri. See: http://webapp-improved.appspot.com/guide/routing.html#building-uris With this information and your knowledge of the app.yaml you can compute the uri for the static url.

In your main.app you add a dummy route definition for static. It will only be used to build the uri and it will never be used for routing.

Modified example from the webapp2 docs :

app = webapp2.WSGIApplication([
    webapp2.Route('/', handler='HomeHandler', name='home'),
    webapp2.Route('/static', handler=HomeHandler, name='static'), # never used for routing
])

Upvotes: 1

aschmid00
aschmid00

Reputation: 7158

no there is no way to query, loop or find out what is in a folder that was uploaded as static.

but the static files do not change as long as you wont deploy the app with new static files.

you need to keep of the static files and compose those absolute urls yourself

Upvotes: 0

Related Questions