Static files in OneGov applications are served under /static.

By default the /static folder of the application is used, relative to the path of the application class. Files in that folder are available to everyone if enabled:

from onegov.core.framework import Framework

class App(Framework):
    serve_static_files = True

By default, the /static path is registered, but returns 404s. This prevents accidental serving of static files.

To change the path to be served have a look at onegov.core.framework.Framework.static_files().

Note that this is not meant to serve css/javascript files, rather it’s a way to serve images, documents and other things that are really static.

Files served through this mechanism support the If-Modified-Since header.

If you need to serve something on another path you can:

class Favicon(StaticFile):

@App.path(model=Favicon, path='favicon.ico')
def get_favicon(app, absorb):
    return StaticFile.from_application(app, 'favicon.ico')



Defines a static file served by the application.


get_static_file(→ StaticFile | None)

view_static_file(→ str | None)

Renders the given static file in the browser.

Module Contents

class core.static.StaticFile(path: str, version: str | None = None)[source]

Defines a static file served by the application.

property absorb: str[source]
classmethod from_application(app: onegov.core.framework.Framework, absorb: str) Self | None[source]

Absorbs all /static/* paths and returns StaticFile instances with the path set to a subpath of onegov.core.Framework.static_files().

For security reasons this subpath is required to actually be inside the static_files folder. No symlinks are allowed.

core.static.get_static_file(app: onegov.core.framework.Framework, absorb: str) StaticFile | None[source]
core.static.view_static_file(self: StaticFile, request: core.request.CoreRequest) str | None[source]

Renders the given static file in the browser.