Template context¶
This page documents the variables that are available to custom templates for each of Datasette's pages. See Custom templates for how to provide your own templates.
The variables documented here are a stable contract: custom templates that use them will continue to work across Datasette releases, up until the next major version (Datasette 2.0). Anything present in the template context but not documented on this page is not part of that contract and may change or be removed in any release.
The pages listed under Debugging tools at the end are the exception. They are documented for reference, but are not covered by that contract.
You can inspect the full context for any page by starting Datasette with
--setting template_debug 1 and adding ?_context=1 to the page URL.
This shows each variable with its documentation and current value - see
template_debug.
Base context¶
These variables are available on every page rendered by Datasette, including pages rendered by plugins that use datasette.render_template(). Plugins can add additional variables using the extra_template_vars(template, database, table, columns, view_name, request, datasette) hook.
requestThe current Request object, or None. Common properties include
request.path,request.args,request.actor,request.url_varsandrequest.host.crumb_itemsAsync function returning breadcrumb navigation items for the current page. Call it with
request=requestplus optionaldatabase=andtable=arguments; it returns a list of{"href": url, "label": label}dictionaries.urlsObject with methods for constructing URLs within Datasette. Common methods include
urls.instance(),urls.database(database),urls.table(database, table),urls.query(database, query),urls.row(database, table, row_path),urls.static(path)andurls.modify(request, ...)for links that change the current query string - see datasette.urls.actorThe currently authenticated actor dictionary, or None. Actors usually include an
idkey and may include any other keys supplied by authentication plugins.menu_linksAsync function returning links for the Datasette application menu, including links added by plugins. Each item is a link dictionary with
hrefandlabelkeys. See menu_links(datasette, actor, request); for page action menus that can also include JavaScript-backed buttons, see Action hooks.display_actorFunction that accepts an actor dictionary and returns the display string used in the navigation menu.
show_logoutTrue if the logout link should be shown in the navigation menu
zipPython's
zip()builtin, made available to template logicbody_scriptsList of JavaScript snippets contributed by plugins using extra_body_script(template, database, table, columns, view_name, request, datasette). Each item is a dictionary with
scriptcontaining JavaScript source andmoduleindicating whether Datasette will wrap it in<script type="module">; otherwise Datasette wraps it in a regular<script>block.show_messagesFunction returning any messages set for the current user, clearing them in the process. Returns a list of
(message, type)pairs, wheretypeis one of Datasette'sINFO,WARNINGorERRORconstants.extra_css_urlsList of extra CSS stylesheets to include on the page. Each item is a dictionary with
urland optionalsrikeys, from plugins and configuration.extra_js_urlsList of extra JavaScript URLs to include on the page. Each item is a dictionary with
urlplus optionalsriandmodulekeys, from plugins and configuration.base_urlThe configured base_url setting
datasette_versionThe version of Datasette that is running
Index page¶
The homepage, listing the tables, views and queries across every database. Rendered using the index.html template.
alternate_url_json-strURL of the JSON version of this page:
/.jsonfollowed by the current query stringcatalog-CatalogThe full catalog object:
itemsandqueries(see below),total(tables and views matching the search and database filter, across all pages),queries_total,databasesandtotals(a dictionary ofdatabases,tablesandviewscounts)database_filter-str | NoneName of the database the list is filtered to with
?database=, or Nonedatabase_url-CallableFunction that takes a database name, or None for all databases, and returns the homepage URL filtered to that database, keeping the current search
databases-list[dict]One dictionary per database the actor can see, in the order they were attached, with keys
name,color,private,tablesandviews(counts matching the current search),urlandsize(bytes, or None for in-memory databases)homepage_actions-list[dict]Links for the homepage actions menu, from plugins implementing homepage_actions(datasette, actor, request)
items-list[dict]The tables and views on this page. Each is a dictionary with
database,name,type(tableorview),private,title,description,columns(up to eight column names),more_columns(the rest of the column names),matched_columns(those matching the search),column_count,linked_tables(other tables linked to or from by a foreign key),has_fts,count,count_truncated,urlandcolor.countis None if counting took too longmetadata-dictInstance metadata, such as
title,descriptionandlicensenext_url-str | NoneURL of the next page, or None on the last page
noindex-boolTrue for the
/-/alternative homepage, which should not be indexed by search enginesother_results-list[dict]While searching, items added to the Jump to menu by plugins using jump_items_sql(datasette, actor, request) that match the search, excluding databases, tables, views and queries. Each has
name,url,typeanddescriptionkeyspage-intThe current page of tables and views, from
?page=page_count-intThe total number of pages
previous_url-str | NoneURL of the previous page, or None on the first page
private-boolTrue if anonymous users cannot view this instance
q-strThe current search, from
?q=queries-list[dict]Up to five stored queries. Without a search these are queries from configuration or plugins, then the actor's own saved queries; with a search, any matching query the actor can see. Each is a dictionary with
database,name,title,description,sql,is_write,private,parameters,url,colorandmineselect_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
top_homepage-CallableFunction returning HTML from plugins that implement top_homepage(datasette, request)
Database page¶
The page listing the tables, views and queries in a database, e.g. /fixtures. Rendered using the database.html template.
allow_download-boolBoolean indicating if database download is allowed
allow_execute_sql-boolBoolean indicating if custom SQL can be executed
alternate_url_json-strURL for the alternate JSON version of this page
attached_databases-listList of names of databases attached to this SQLite connection. This is only populated for the special
/_memorydatabase when Datasette is started with--crossdbfor Cross-database queries.database-strThe name of the database
database_actions-callableAsync callable returning action items for the database menu. Each item is either a link with
href,labeland optionaldescriptionkeys, or a button withtype: "button",label, optionaldescriptionand optionalattrs. See Action hooks and database_actions(datasette, actor, database, request).database_color-strThe color assigned to the database
database_page_data-dictJSON data used by JavaScript on the database page. Currently
{}or{"createTable": {...}}wherecreateTableincludespath,foreignKeyTargetsPath,databaseName,columnTypes,defaultExpressions,canInsertRowsand optionalcustomColumnTypes.hidden_count-intCount of hidden tables
metadata-dictMetadata dictionary for the database, such as
title,description,licenseandsourcevalues from Datasette metadata.private-boolBoolean indicating if this is a private database
queries-list[StoredQuery]List of
StoredQueryobjects. Each has attributes includingname,sql,title,description,description_html,hide_sql,fragment,parameters,is_writeandprivate.queries_count-intCount of visible stored queries
select_templates-listList of template names that were considered for this page, with the selected template prefixed by
*.show_hidden-strValue of _show_hidden query parameter
size-intThe size of the database in bytes
table_columns-dictDictionary mapping table names to lists of column names, used to power SQL autocomplete.
tables-list[DatabaseTable]List of
DatabaseTableobjects describing tables in the database. Each item hasname,columns,primary_keys,count,count_truncated,hidden,fts_table,foreign_keysandprivateattributes.count_truncatedis true ifcountis a capped lower bound rather than an exact total.top_database-callableAsync callable that renders the
top_databaseplugin slot for this database and returns HTML.views-list[DatabaseViewInfo]List of
DatabaseViewInfoobjects describing SQLite views in the database. Each item hasnameandprivateattributes.
Query page¶
The page for arbitrary SQL queries (/database/-/query?sql=...) and stored queries (/database/query-name). Rendered using the query.html template.
allow_execute_sql-boolBoolean indicating if custom SQL can be executed
alternate_url_json-strURL for alternate JSON version of this page
columns-listList of result column names in the order they appear in
display_rowsandrows.database-strThe name of the database being queried
database_color-strThe color of the database
db_is_immutable-boolBoolean indicating if this database is immutable
display_rows-listList of result rows formatted for HTML display. Each row is a list of rendered cell values in the same order as
columns.edit_sql_url-strURL to edit the SQL for a stored query
editable-boolBoolean indicating if the SQL can be edited
error-strAny query error message
hide_sql-boolBoolean indicating if the SQL should be hidden
metadata-dictMetadata dictionary for the database or stored query. Stored query metadata may include options such as
hide_sql,on_success_messageandon_error_redirect.named_parameter_values-dictDictionary of named SQL parameter values, keyed by parameter name without the leading
:.private-boolBoolean indicating if this is a private database
query-dictDictionary describing the SQL query being executed, with
sqlandparamskeys.query_actions-callableAsync callable returning action items for the query menu. Each item is either a link with
href,labeland optionaldescriptionkeys, or a button withtype: "button",label, optionaldescriptionand optionalattrs. See Action hooks and query_actions(datasette, actor, database, query_name, request, sql, params).query_page_data-dictJSON data used by the column statistics dialog on the query page, or
Noneif it is not available. It is only provided for read-only queries that returned rows, use no magic parameters and are run by an actor who can execute custom SQL. HasdatabaseandexecuteSqlkeys.executeSqlhasqueryUrlandeditorUrl, aquerywith thesql, itsparamsandshownRows, the number of rows shown on the page, andcolumns: the result columns with uniquenamevalues and the SQLite storagetypeseen in the returned rows (mixedif more than one).renderer_options-dictDictionary mapping output format names to the
label,description,is_binaryandis_webpageoptions their register_output_renderer(datasette) plugin hook set, used by the export dialog.renderers-dictDictionary mapping output format names such as
jsonto URLs for this query in that format.save_query_url-strURL to save the current arbitrary SQL as a query
select_templates-listList of template names that were considered for this page, with the selected template prefixed by
*.show_hide_hidden-strRendered hidden
<input>HTML preserving the current_hide_sqlor_show_sqlstate.show_hide_link-strThe URL to toggle showing/hiding the SQL
show_hide_text-strThe text for the show/hide SQL link
stored_query-strThe name of the stored query if this is a stored query
stored_query_write-boolBoolean indicating if this is a stored query that allows writes
table_columns-dictDictionary mapping table names to lists of column names, used to power SQL autocomplete.
tables-list[DatabaseTable]List of
DatabaseTableobjects describing tables in the database. Each item hasname,columns,primary_keys,count,count_truncated,hidden,fts_table,foreign_keysandprivateattributes.count_truncatedis true ifcountis a capped lower bound rather than an exact total.top_query-callableAsync callable that renders the
top_queryplugin slot for this query and returns HTML.top_stored_query-callableAsync callable that renders the
top_stored_queryplugin slot for stored queries and returns HTML.truncated-boolBoolean indicating if the results were truncated at the
max_returned_rowslimiturl_csv-strURL for CSV export
url_csv_hidden_args-listList of
(name, value)pairs for hidden form fields used by the CSV export form, preserving the SQL and parameters while forcing_size=max.url_csv_path-strPath portion of the CSV export URL
url_tsv_path-strPath portion of the TSV export URL, which takes the same arguments as CSV, or None if a plugin provides the
tsvformat
Table page¶
The page showing the rows in a table or SQL view, e.g. /fixtures/facetable. Rendered using the table.html template.
Many of these keys are shared with the JSON API for this page.
actions-callableAsync callable returning table or view actions made available by core and plugin hooks. Each item is either a link with
href,labeland optionaldescriptionkeys, or a button withtype: "button",label, optionaldescriptionand optionalattrs. See Action hooks, table_actions(datasette, actor, database, table, request) and view_actions(datasette, actor, database, view, request).all_columns-listList of all column names in the table, regardless of
_col=or_nocol=filtering.allow_execute_sql-boolTrue if the current actor can execute custom SQL against this database
alternate_url_json-strURL for the JSON version of this page
clear_filters_url-strURL for this page with all column filters removed, or None if no column filters are applied. Other arguments such as
?_search=,?_where=and?_facet=are preserved.columns-listList of column names returned by this table, row or query.
count-intTotal count of rows matching these filters
count_sql-strSQL query string used to calculate the total count for the current table view, including active filters.
count_truncated-boolTrue if
countis a capped lower bound rather than an exact total, because Datasette stopped counting after its configured row-count limit.custom_table_templates-listList of custom template names considered for rendering table rows, in lookup order.
database-strDatabase name
database_color-strColor assigned to the database
display_columns-listColumn metadata used by the HTML table display. Each item includes
name,sortable,is_pk,type,notnull,description,column_type,column_type_configandhas_fkskeys.has_fksis true when at least one cell in the column is displayed as a link to a foreign key row.display_rows-listRows formatted for the HTML table display. Each row is iterable and contains cell dictionaries with
column,value,rawandvalue_typekeys; table pages may also providepk_path,row_pathandrow_labelattributes on each row object.expandable_columns-listList of foreign key columns that can be expanded with labels. Each item is a
(foreign_key, label_column)pair whereforeign_keyis the SQLite foreign key dictionary andlabel_columnis the label column in the referenced table, orNone.extra_wheres_for_ui-listExtra where clauses from
?_where=for display in the UI. Each item hastextfor the SQL fragment andremove_urlfor a URL that removes that fragment.facet_results-dictResults of facets calculated against this data. A dictionary with
resultsandtimed_outkeys:resultsmaps facet names to facet dictionaries withname,type,resultsand URL keys, and each facet result item includesvalue,label,countandtoggle_url.facets_timed_out-listList of names of facet calculations that exceeded the facet time limit.
filter_columns-listList of column names offered by the filter interface, including currently displayed columns and any hidden columns that can still be filtered.
filter_description_en-strHuman readable description of the filters, search and
?_where=clauses applied to the table, for examplewhere state = "CA", or an empty string if there are none.filters-FiltersFiltersobject used by the HTML table interface. Useful methods includefilters.human_description_en(); this is not JSON serializable.form_hidden_args-listList of
(name, value)pairs for hidden form fields used by the HTML table interface to preserve current query string options.human_description_en-strHuman-readable description of the filters
is_sortable-boolTrue if any of the displayed columns can be used to sort
is_view-boolWhether this resource is a view instead of a table
metadata-dictMetadata dictionary for the table, database or stored query. Table and row metadata include a
columnsdictionary mapping column names to descriptions; stored query metadata returns the stored query configuration.next-strPagination token for the next page, or None
next_url-strFull URL for the next page of results, or None if there are no more pages. See Pagination.
page_position-dictOn pages after the first (
?_next=is set) a dictionary withfirst_url(this page without?_next=),count_before_url(POST to count the rows before this page),after_columnandafter_value(a description of the pagination cursor).Noneon the first page.primary_keys-listList of primary key column names for this table, or an empty list if the table has no explicit primary key.
private-boolWhether this resource is private to the current actor
query-dictDetails of the underlying SQL query as a dictionary with
sqlandparamskeys.query_ms-floatTime taken by the SQL queries for this page, in milliseconds
renderer_options-dictDictionary mapping output format names to the
label,description,is_binaryandis_webpageoptions their register_output_renderer(datasette) plugin hook set, used by the export dialog.renderers-dictDictionary mapping output format names such as
jsonor plugin-provided renderer names to URLs for this data in that format.row_mutation_ui-boolTrue if the current actor can edit or delete rows in this table, which enables the row edit/delete JavaScript UI
rows-listThe rows for this page, as a list of dictionaries mapping column name to raw value.
search-strThe current full-text search from
?_search=, or an empty stringselect_templates-listList of template names that were considered for this page, with the selected template prefixed by
*.set_column_type_ui-dictInformation needed to build an interface for assigning column types, or
Noneif unavailable. When present it haspathandcolumnskeys;columnsmaps column names tocurrentandoptionsvalues.settings-dictDictionary of Datasette's current settings, keyed by setting name.
sort-strColumn the page is sorted by, or None
sort_desc-strColumn the page is sorted by in descending order, or None
sort_description_en-strHuman readable description of the sort order, for example
sorted by name descending, or an empty string if no sort order was specified.sorted_facet_results-listFacet result dictionaries sorted for display. Each item has the same shape as an entry from
facet_results['results'].suggested_facets-listSuggestions for facets that might return interesting results. Each item is a dictionary with
nameandtoggle_urlkeys, and may include extra keys such astypeorlabeldepending on the facet class.supports_search-boolTrue if this table has full-text search configured
table-strTable name
table_alter_ui-dictInformation needed to enable the alter table UI, or
Noneif altering this table is not available to the current actor. When present it haspath,tableName,columns,primaryKeys,columnTypes,defaultExpressionsandforeignKeyTargetsPathkeys, plus optionalcustomColumnTypesanddropPathkeys.table_definition-strSQL definition for this table
table_insert_ui-dictInformation needed to enable the row insertion UI, or
Noneif row insertion is not available to the current actor. When present it haspath,tableName,columns,bulkColumns,primaryKeysandmaxInsertRowskeys, plus optionalupsertPathif the current actor has permission to update rows.columnslists columns for the single-row insert form, whilebulkColumnslists columns for the bulk insert form. Each column includesname,sqlite_type,notnull,default,has_default,is_pk,is_auto_pk,value_kindandcolumn_typekeys.table_page_data-dictJSON data used by JavaScript on the table page. Includes
database,tableandtableUrl, plus optionalforeignKeysmapping column names to autocomplete URLs, optionalinsertRowdata, optionalalterTabledata and optionalexecuteSqldata withqueryUrlandeditorUrlkeys, present if the current actor can execute custom SQL against this database.executeSqlalso has acolumnslist of every column in the table with itsnameand declaredtype, and an optionalfilterkey with thewhereclause,paramsand human readabledescriptionof the filters currently applied to the table.top_table-callableAsync callable that renders the
top_tableplugin slot for this table or view and returns HTML.url_csv-strURL for the CSV export of this page
url_csv_hidden_args-listList of
(name, value)pairs for hidden form fields used by the CSV export form, preserving current filters and any?_next=pagination cursor while forcing_size=max.url_csv_path-strPath portion of the CSV export URL
url_tsv_path-strPath portion of the TSV export URL, which takes the same arguments as CSV, or None if a plugin provides the
tsvformatview_definition-strSQL definition for this view
Row page¶
The page showing an individual row, e.g. /fixtures/facetable/1. Rendered using the row.html template.
Many of these keys are shared with the JSON API for this page.
alternate_url_json-strURL for the JSON version of this page
columns-listList of column names returned by this table, row or query.
custom_table_templates-listCustom template names that were considered for displaying this row's table, in lookup order.
database-strDatabase name
database_color-strColor assigned to the database
display_columns-listColumn metadata used by the HTML table display. Each item includes
name,sortable,is_pk,type,notnull,description,column_type,column_type_configandhas_fkskeys.has_fksis true when at least one cell in the column is displayed as a link to a foreign key row.display_rows-listRows formatted for the HTML table display. Each row is iterable and contains cell dictionaries with
column,value,rawandvalue_typekeys.foreign_key_tables-listList of tables that link to this row using foreign keys. Each item includes the foreign key fields plus
countfor matching rows andlinkfor the filtered table URL.metadata-dictMetadata dictionary for the table, database or stored query. Table and row metadata include a
columnsdictionary mapping column names to descriptions; stored query metadata returns the stored query configuration.primary_key_values-listValues of the primary keys for this row, decoded from the URL. Most are strings. A binary value is
bytes, and a number in a primary key column with no declared type is anintorfloat. Use thekey_value_displayfilter to show one.primary_keys-listList of primary key column names for this table, or an empty list if the table has no explicit primary key.
private-boolWhether this resource is private to the current actor
query_ms-floatTime taken by the SQL queries for this page, in milliseconds
renderer_options-dictDictionary mapping output format names to the
label,description,is_binaryandis_webpageoptions their register_output_renderer(datasette) plugin hook set, used by the export dialog.renderers-dictDictionary mapping output format names such as
jsonto URLs for this row in that format.row_actions-listRow actions made available by core and plugin hooks. Each item is either a link with
href,labeland optionaldescriptionkeys, or a button withtype: "button",label, optionaldescriptionand optionalattrs. See Action hooks and row_actions(datasette, actor, request, database, table, row).row_mutation_ui-boolTrue if the row edit/delete JavaScript UI should be enabled
rows-listA single-item list containing this row as a dictionary mapping column name to raw value.
select_templates-listList of template names that were considered for this page, with the selected template prefixed by
*.settings-dictDictionary of Datasette's current settings, keyed by setting name.
table-strTable name
table_page_data-dictJSON data used by JavaScript on the row page. Includes
database,tableandtableUrl, plus optionalforeignKeysmapping column names to autocomplete URLs.top_row-callableAsync callable that renders the
top_rowplugin slot for this row and returns HTML.url_csv-strURL for the CSV export of this page
url_csv_hidden_args-listList of
(name, value)pairs for hidden form fields used by the CSV export form, preserving current options.url_csv_path-strPath portion of the CSV export URL
url_tsv_path-strPath portion of the TSV export URL, which takes the same arguments as CSV, or None if a plugin provides the
tsvformat
Query list page¶
The list of stored queries, at /-/queries for every database and /<database>/-/queries for one database. Rendered using the query_list.html template.
actor_id-str | NoneID of the current actor, or None
all_queries_href-str | NoneURL of the list covering every database, keeping the current search and filters
alternate_url_json-strURL of the JSON version of this page
database-str | NoneName of the database the list is for, or None for the list covering every database
database_chips-list[dict]Links for switching between databases, each with
name,count,color,selectedandhrefkeys. Empty if fewer than two databases have queriesdatabase_color-str | NoneColor assigned to the database, or None
facets-list[dict]Filters shown next to the list. Each has a
titleand a list ofitems, each withlabel,count,href(to toggle the filter, or None) andactivekeysfilters-dictThe current values of the
q,is_write,is_private,sourceandowner_idquery string arguments, as strings that are empty if not setnext-str | NonePagination token for the next page, or None
next_url-str | NoneURL of the next page of queries, or None
queries-list[StoredQuery]The stored queries on this page that the actor can see. Each has
database,name,sql,title,description,description_html,parameters,is_write,is_private,is_trusted,sourceandowner_idattributesquery_list_path-strPath to this list without its query string, used as the action for the search form
query_parameters-dictDictionary mapping
(database, name)tuples to the list of named parameters for that queryselect_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
start-intNumber of queries on earlier pages, used to display the position of this page
total-intNumber of queries matching the current search and filters, across all pages
Query create page¶
The form for saving a new stored query, at /<database>/-/queries/store. Rendered using the query_create.html template.
analysis_error-str | NoneError message if the SQL could not be analyzed, for example because it is not valid, otherwise None
analysis_is_write-boolTrue if the SQL writes to the database
analysis_rows-list[dict]The operations the SQL would perform, one per table it reads or writes. Each has
operation,database,table,required_permission,message,sourceandallowedkeys.allowedis False if the actor may not perform that operation, and None for operations that need no permission checkdatabase-strDatabase name
database_color-strColor assigned to the database
description-strThe description entered for the query
has_sql-boolTrue if any SQL has been entered
is_private-boolTrue if the private checkbox should be checked
name-strThe name entered for the query, used in its URL
save_disabled-boolTrue if the query cannot be saved, because there is no SQL, it could not be analyzed or the actor lacks a permission it needs
select_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
sql-strThe SQL for the query
title-strThe title entered for the query
Query edit page¶
The form for editing a stored query, at /<database>/<query>/-/edit. Rendered using the query_edit.html template.
analysis_error-str | NoneError message if the SQL could not be analyzed, for example because it is not valid, otherwise None
analysis_is_write-boolTrue if the SQL writes to the database
analysis_rows-list[dict]The operations the SQL would perform, one per table it reads or writes. Each has
operation,database,table,required_permission,message,sourceandallowedkeys.allowedis False if the actor may not perform that operation, and None for operations that need no permission checkdatabase-strDatabase name
database_color-strColor assigned to the database
description-strThe description of the query, or an empty string
has_sql-boolTrue if any SQL has been entered
is_private-boolTrue if the private checkbox should be checked
name-strName of the query being edited
query_url-strURL of the page for the query
save_disabled-boolTrue if the query cannot be saved, because there is no SQL, it could not be analyzed or the actor lacks a permission it needs
select_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
sql-strThe SQL for the query
title-strThe title of the query, or an empty string
Query delete page¶
The page asking for confirmation before deleting a stored query, at /<database>/<query>/-/delete. Rendered using the query_delete.html template.
database-strDatabase name
database_color-strColor assigned to the database
query-dictThe query to be deleted, a dictionary with keys including
name,sql,title,description,is_write,is_privateandowner_idquery_url-strURL of the page for the query
select_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
Execute write page¶
The form for running SQL that writes to a database, at /<database>/-/execute-write. Rendered using the execute_write.html template.
analysis_error-str | NoneError message if the SQL could not be analyzed or is not a write, otherwise None
analysis_rows-list[dict]The operations the SQL would perform, one per table it reads or writes. Each has
operation,database,table,required_permission,message,sourceandallowedkeys.allowedis False if the actor may not perform that operationdatabase-strDatabase name
database_color-strColor assigned to the database
execute_disabled-boolTrue if the SQL cannot be executed as it stands
execute_disabled_reason-str | NoneWhy the SQL cannot be executed, or None if it can or if that reason is already displayed as the error for this request
execute_write_columns-list[str]Names of the columns of the returned rows
execute_write_display_rows-listThe returned rows, formatted for display in the same way as
display_rowson the query pageexecute_write_returns_rows-boolTrue if the executed SQL returned rows, for example by using
RETURNINGexecute_write_truncated-boolTrue if more rows were returned than are displayed
execution_links-list[dict]Links to show after the SQL was executed, such as to a row that was inserted. Each has
hrefandlabelkeysexecution_message-str | NoneMessage describing the result of executing the SQL, or None if nothing has been executed
execution_ok-bool | NoneTrue if the SQL was executed, False if it failed and None if nothing has been executed
parameter_names-list[str]Names of the
:namedparameters found in the SQLparameter_values-dictDictionary mapping parameter names to the values that were submitted for them
save_query_base_url-str | NoneURL of the form for saving a stored query without any SQL filled in, or None if the actor cannot save queries
save_query_url-str | NoneURL for saving this SQL as a stored query, or None if the actor cannot do that or the SQL cannot be executed
select_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
sql-strThe SQL in the editor
sql_parameter_name_prefix-strPrefix added to the name of each parameter to make the name of its form field
table_columns-dictDictionary mapping the name of each table and view in the database to a list of its column names, used for autocomplete in the editor
write_create_table_template_sql-str | NoneExample
CREATE TABLESQL, or None if the actor cannot create tableswrite_template_operations-list[dict]The operations that have example SQL for at least one table, each with
nameandlabelkeyswrite_template_tables-dictTables the actor can write to. Maps each table name to a dictionary with a
templateskey, itself a dictionary mapping an operation such asinsertto example SQL for that operation
Schema page¶
The schema pages: /-/schema for every database, /<database>/-/schema for one database and /<database>/<table>/-/schema for one table. Rendered using the schema.html template.
is_instance-boolTrue on the page showing the schema of every database
schemas-list[dict]One dictionary per database, with
database(its name) andschema(the SQL that creates the tables and views the actor can see). The table page has a single item holding the SQL for just that tableselect_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
table_name-str | NoneName of the table on the page for a single table, or None
Create token page¶
The form for creating an API token, at /-/create-token. Rendered using the create_token.html template.
all_actions-list[str]Names of every action, which the token can be restricted to across the whole instance
child_actions-list[str]Names of the actions that can be restricted to a specific table or other resource in a database
database_actions-list[str]Names of the actions that can be restricted to a specific database
database_with_tables-list[dict]The databases the actor can see. Each has
name,encoded(the name encoded for use in a form field) andtables, a list of dictionaries withnameandencodedkeyserrors-list[str]Error messages from validating the submitted form
select_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
token-str | NoneThe token that was created, or None if the form has not been successfully submitted
token_bits-dict | NoneThe decoded contents of the token that was created, or None
API explorer page¶
The API explorer, a tool for trying out the JSON API, at /-/api. Rendered using the api_explorer.html template.
api_path-CallableFunction that takes one of those links and returns the URL of the API explorer with the form filled in for it
example_links-list[dict]Example API calls for the databases the actor can see. Each database has
name,linksandtableskeys, and each table hasnameandlinks. A link haslabel,methodandpathkeys, plusjsonholding an example request body for write APIsprivate-boolTrue if anonymous users cannot view this instance
select_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
Logout page¶
The page asking the actor to confirm that they want to log out, at /-/logout. It has no variables of its own - the actor is the actor variable available on every page. Rendered using the logout.html template.
select_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
JSON data pages¶
The pages that display JSON describing the instance, such as /-/versions, /-/plugins, /-/settings, /-/config, /-/databases, /-/threads and /-/actor. /-/actions uses the same variables with the debug_actions.html template. Rendered using the show_json.html template.
alternate_url_json-strURL of the JSON version of this page
data-dict | listThe data for this page, as returned by its JSON API
data_json-strThat data as a string of indented JSON
filename-strName of the JSON file for this page, such as
versions.json, used as the page titlehas_debug_permission-boolTrue if this page requires the
permissions-debugpermission, in which case links to the other permission debugging tools are shownselect_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
Error page¶
The page shown for an error, such as a 404 or a 500. Datasette looks for a template named after the status code first, so 404.html can be used to customize just that error. Rendered using the error.html template.
Error pages other than the 403 permission denied page are rendered without most of the variables that are available on every page - only urls and menu_links are provided. Errors raised by plugins can include additional variables of their own.
error-strThe error message
status-intThe HTTP status code, for example
404title-str | NoneTitle for the page, or None to use the default of
Errorfollowed by the status code
CSRF error page¶
The page shown when a form submission is rejected by Datasette's CSRF protection. Rendered using the csrf_error.html template.
reason-strTechnical explanation of why the request was rejected, intended for developers
Debugging tools¶
These pages are tools for debugging a Datasette instance. Their variables are documented here for reference but are not part of the stable contract described at the top of this page: they may change or be removed in any release.
Autocomplete debug page¶
A tool for trying out the autocomplete for the rows of a table, at /-/debug/autocomplete. Rendered using the debug_autocomplete.html template.
autocomplete_url-str | NoneURL of the autocomplete API for the table, or None if no table has been selected
database_name-str | NoneName of the database from
?database=, or Noneerror-str | NoneError message if the database or table could not be found, otherwise None
label_column-str | NoneThe label column for the table, which autocomplete searches against, or None
reached_scan_limit-boolTrue if the search for suggestions stopped because it reached its limit of 100 tables
scanned-intNumber of tables examined while looking for suggestions
select_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
suggestions-list[dict]Up to five tables with a label column to try, shown if no table has been selected. Each has
database,table,label_columnandurlkeystable_name-str | NoneName of the table from
?table=, or None
Permissions debug page¶
The permissions playground at /-/permissions, which lists recent permission checks and has a form for testing a permission check against any actor. Rendered using the debug_permissions_playground.html template.
filter-strWhich checks are listed, from
?filter=:all,exclude-yoursoronly-yourshas_debug_permission-boolTrue if the actor has the
permissions-debugpermission, in which case links to the other permission debugging tools are shownpermission_checks-listRecent permission checks, most recent first. Each has
when,actor,action,parent,childandresultattributes.resultis None if no rule had an opinionpermissions-list[dict]Every registered action, each with
name,abbr,description,takes_parentandtakes_childkeysselect_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
Allowed resources page¶
A tool for listing the resources the current actor can access for a given action, at /-/allowed. Rendered using the debug_allowed.html template.
has_debug_permission-boolTrue if the actor has the
permissions-debugpermission, in which case links to the other permission debugging tools are shownselect_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
supported_actions-list[str]Names of every registered action, with the most commonly used ones first
Permission rules page¶
A tool for viewing the permission rules that apply to the current actor for a given action, at /-/rules. Rendered using the debug_rules.html template.
has_debug_permission-boolTrue if the actor has the
permissions-debugpermission, in which case links to the other permission debugging tools are shownselect_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
sorted_actions-list[str]Names of every registered action, in alphabetical order
Permission check page¶
A tool for testing whether an actor can perform an action against a resource, with an explanation of the result, at /-/check. Rendered using the debug_check.html template.
actions-list[dict]Every registered action in alphabetical order, each with
name,description,takes_parent,takes_childandalso_requireskeysactor_json-strJSON for the actor to test, from
?actor=or otherwise the current actorhas_debug_permission-boolTrue if the actor has the
permissions-debugpermission, in which case links to the other permission debugging tools are shownselect_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
Allow debug page¶
A tool for testing an actor against an allow block, at /-/allow-debug. Rendered using the allow_debug.html template.
actor_input-strJSON for the actor to test, from
?actor=allow_input-strJSON for the allow block to test, from
?allow=error-strError messages for input that was not valid JSON, or an empty string
has_debug_permission-boolTrue if the actor has the
permissions-debugpermission, in which case links to the other permission debugging tools are shownresult-str | None"True"if the actor matches the allow block,"False"if it does not, or None if either input was not valid JSONselect_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used
Messages debug page¶
A tool for setting a message to be shown on the next page, at /-/messages. It has no variables of its own. Rendered using the messages_debug.html template.
select_templates-list[str]The template names Datasette considered, with an asterisk next to the one that was used