Using static files

Usually web applications make use of CSS and JavaScript resources to provide a better user experience. For efficiency reasons, such content is not dynamically served by the WSGI application and are delivered by App Engine as static files instead.

We know from the previous chapter that App Engine provides two types of handlers, script handlers and static file handlers. We add a static file handler to our app.yaml configuration file like this:

handlers:
- url: /static
  static_dir: static

- url: .*
  script: main.app

The syntax is almost the same as for script handlers. We specify a URL to map as a regular expression but instead of providing a Python script to handle requests, we specify a filesystem path relative to the application ...

Get Python for Google App Engine now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.