Houdini 20.5 Python scripting hou hou.webServer

hou.webServer.registerStaticFilesDirectory HOM function

Tells Houdini’s web server to check the given directory for files to automatically serve for URLs that match the given path prefix.

registerStaticFilesDirectory(directory, url_prefix="/static")

When the server receives a request whose path starts with url_prefix, if the remaining part of the request path, appended to the directory path, is a file that exists, the server will automatically serve that file to the client.

Call this function before you call hou.webServer.run(), not from a URL handler.

For example, if you do this:

hou.webServer.registerStaticFilesDirectory("/var/www/files", "/static")

…and the client requests this server path:

/static/css/main.css

…and this file exists:

/var/www/files/css/main.css

…then the server will automatically serve the main.css file to the client without involving a Python handler.

You should try to set up the server so it serves any static files (files that are not generated dynamically from Houdini data, for example CSS and JavaScript files) this way, rather than in a Python handler.

Note

If a URL handler has a URL is more specific (matches more path parts) than the static path prefix, the server will use the handler instead of static lookup.

For example, even if you registered the static directory above, if the client requested /static/geo/foo.bgeo and you have a dynamic handler for /static/geo, the server would use the handler instead of looking for a static file.

This might be useful if you need a few dynamically generated resources mixed in with otherwise static files in the server namespace. However, it’s usually best to avoid the confusion and keep static resources separate from dynamic resources, such as by using the default /static prefix for static files.

See also

hou.webServer

Classes

Starting and Stopping

Handling Web Requests and Returning Responses

API Calls

  • hou.webServer.apiFunction()

    Decorator for functions that can be called through an API endpoint on Houdini’s web server, returning JSON or binary responses.

  • hou.webServer.APIError

    Raise this exception in apiFunction handlers to indicate an error.