home / docs / sections

sections: writing_plugins:writing-plugins-static-assets

This data as json

id page ref title content breadcrumbs references
writing_plugins:writing-plugins-static-assets writing_plugins writing-plugins-static-assets Static assets If your plugin has a static/ directory, Datasette will automatically configure itself to serve those static assets from the following path: /-/static-plugins/NAME_OF_PLUGIN_PACKAGE/yourfile.js Use the datasette.urls.static_plugins(plugin_name, path) method to generate URLs to that asset that take the base_url setting into account, see datasette.urls . To bundle the static assets for a plugin in the package that you publish to PyPI, add the following to the plugin's setup.py : package_data = ( { "datasette_plugin_name": [ "static/plugin.js", ], }, ) Where datasette_plugin_name is the name of the plugin package (note that it uses underscores, not hyphens) and static/plugin.js is the path within that package to the static file. datasette-cluster-map is a useful example of a plugin that includes packaged static assets in this way. See Writing custom CSS for tips on writing CSS that is compatible with Datasette's default CSS, including details of the core class for applying Datasette's default form element styles. ["Writing plugins"] [{"href": "https://github.com/simonw/datasette-cluster-map", "label": "datasette-cluster-map"}]
Powered by Datasette · Queries took 1.251ms