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 |