Skip to main content
Community

UI Components

New in NetBox v4.6

All UI components described here were introduced in NetBox v4.6. Be sure to set the minimum NetBox version to 4.6.0 for your plugin before incorporating any of these resources.

To simplify the process of designing your plugin's user interface, and to encourage a consistent look and feel throughout the entire application, NetBox provides a set of components that enable programmatic UI design. These make it possible to declare complex page layouts with little or no custom HTML.

Page Layout

A layout defines the general arrangement of content on a page into rows and columns. The layout is defined under the view and declares a set of rows, each of which may have one or more columns. Below is an example layout.

+-------+-------+-------+
| Col 1 | Col 2 | Col 3 |
+-------+-------+-------+
| Col 4 |
+-----------+-----------+
| Col 5 | Col 6 |
+-----------+-----------+

The above layout can be achieved with the following declaration under a view:

from netbox.ui import layout
from netbox.views import generic

class MyView(generic.ObjectView):
layout = layout.Layout(
layout.Row(
layout.Column(),
layout.Column(),
layout.Column(),
),
layout.Row(
layout.Column(),
),
layout.Row(
layout.Column(),
layout.Column(),
),
)
note

Currently, layouts are supported only for subclasses of generic.ObjectView.

Layout

A collection of rows and columns comprising the layout of content within the user interface.

SimpleLayout

Bases: Layout

A layout with one row of two columns and a second row with one column. Plugin content registered for left_page, right_page, or full_width_page is included automatically. Most object views in NetBox utilize this layout. +-------+-------+ | Col 1 | Col 2 | +-------+-------+ | Col 3 | +---------------+

Row

A collection of columns arranged horizontally.

Column

A collection of panels arranged vertically.

Panels

Within each column, related blocks of content are arranged into panels. Each panel has a title and may have a set of associated actions, but the content within is otherwise arbitrary.

Plugins can define their own panels by inheriting from the base class netbox.ui.panels.Panel. Override the get_context() method to pass additional context to your custom panel template. An example is provided below.

from django.utils.translation import gettext_lazy as _
from netbox.ui.panels import Panel

class RecentChangesPanel(Panel):
template_name = 'my_plugin/panels/recent_changes.html'
title = _('Recent Changes')

def get_context(self, context):
return {
**super().get_context(context),
'changes': get_changes()[:10],
}

def should_render(self, context):
return len(context['changes']) > 0

NetBox also includes a set of panels suited for specific uses, such as displaying object details or embedding a table of related objects. These are listed below.

Panel

A block of content rendered within an HTML template. Panels are arranged within rows and columns, (generally) render as discrete "cards" within the user interface. Each panel has a title and may have one or more actions associated with it, which will be rendered as hyperlinks in the top right corner of the card.

get_context(context)

Return the context data to be used when rendering the panel.

Parameters:

NameTypeDescriptionDefault
contextAnyNo description available-

should_render(context)

Determines whether the panel should render on the page. (Default: True).

Parameters:

NameTypeDescriptionDefault
contextAnyNo description available-

render(context)

Render the panel as HTML.

Parameters:

NameTypeDescriptionDefault
contextAnyNo description available-

ObjectPanel

Bases: Panel

Base class for object-specific panels.

ObjectAttributesPanel

Bases: ObjectPanel

A panel which displays selected attributes of an object. Attributes are added to the panel by declaring ObjectAttribute instances in the class body (similar to fields on a Django form). Attributes are displayed in the order they are declared. Note that the only and exclude parameters are mutually exclusive.

OrganizationalObjectPanel

Bases: ObjectAttributesPanel

An ObjectPanel with attributes common to OrganizationalModels. Includes name and description attributes.

NestedGroupObjectPanel

Bases: ObjectAttributesPanel

An ObjectPanel with attributes common to NestedGroupObjects. Includes the parent attribute.

CommentsPanel

Bases: ObjectPanel

A panel which displays comments associated with an object.

JSONPanel

Bases: ObjectPanel

A panel which renders formatted JSON data from an object's JSONField.

RelatedObjectsPanel

Bases: Panel

A panel which displays the types and counts of related objects.

ObjectsTablePanel

Bases: Panel

A panel which displays a table of objects (rendered via HTMX).

should_render(context)

Hide the panel if the user does not have view permission for the panel's model.

Parameters:

NameTypeDescriptionDefault
contextAnyNo description available-

TemplatePanel

Bases: Panel

A panel which renders custom content using an HTML template.

TextCodePanel

Bases: ObjectPanel

A panel displaying a text field as a pre-formatted code block.

ContextTablePanel

Bases: ObjectPanel

A panel which renders a django-tables2/NetBoxTable instance provided via the view's extra context. This is useful when you already have a fully constructed table (custom queryset, special columns, no list view) and just want to render it inside a declarative layout panel.

PluginContentPanel

Bases: Panel

A panel which displays embedded plugin content.

Panel Actions

Each panel may have actions associated with it. These render as links or buttons within the panel header, opposite the panel's title. For example, a common use case is to include an "Add" action on a panel which displays a list of objects. Below is an example of this.

from django.utils.translation import gettext_lazy as _
from netbox.ui import actions, panels

panels.ObjectsTablePanel(
model='dcim.Region',
title=_('Child Regions'),
filters={'parent_id': lambda ctx: ctx['object'].pk},
actions=[
actions.AddObject('dcim.Region', url_params={'parent': lambda ctx: ctx['object'].pk}),
],
),

PanelAction

A link (typically a button) within a panel to perform some associated action, such as adding an object.

get_context(context)

Return the template context used to render the action element.

Parameters:

NameTypeDescriptionDefault
contextAnyNo description available-

render(context)

Render the action as HTML.

Parameters:

NameTypeDescriptionDefault
contextAnyNo description available-

LinkAction

Bases: PanelAction

A hyperlink (typically a button) within a panel to perform some associated action, such as adding an object.

get_url(context)

Resolve the URL for the action from its view name and kwargs. Append any additional URL parameters.

Parameters:

NameTypeDescriptionDefault
contextAnyNo description available-

AddObject

Bases: LinkAction

An action to add a new object.

CopyContent

Bases: PanelAction

An action to copy the contents of a panel to the clipboard.

Object Attributes

The following classes are available to represent object attributes within an ObjectAttributesPanel. Additionally, plugins can subclass netbox.ui.attrs.ObjectAttribute to create custom classes.

ClassDescription
netbox.ui.attrs.AddressAttrA physical or mailing address.
netbox.ui.attrs.ArrayAttrAn array of values, shown as a comma-separated list
netbox.ui.attrs.BooleanAttrA boolean value
netbox.ui.attrs.ChoiceAttrA selection from a set of choices
netbox.ui.attrs.ColorAttrA color expressed in RGB
netbox.ui.attrs.DateTimeAttrA date or datetime value
netbox.ui.attrs.GenericForeignKeyAttrA related object via a generic foreign key
netbox.ui.attrs.GPSCoordinatesAttrGPS coordinates (latitude and longitude)
netbox.ui.attrs.ImageAttrAn attached image (displays the image)
netbox.ui.attrs.NestedObjectAttrA related nested object (includes ancestors)
netbox.ui.attrs.NumericAttrAn integer or float value
netbox.ui.attrs.RelatedObjectAttrA related object
netbox.ui.attrs.RelatedObjectListAttrA list of related objects
netbox.ui.attrs.TemplatedAttrRenders an attribute using a custom template
netbox.ui.attrs.TextAttrA string (text) value
netbox.ui.attrs.TimezoneAttrA timezone with annotated offset
netbox.ui.attrs.UtilizationAttrA numeric value expressed as a utilization graph

ObjectAttribute

Base class for representing an attribute of an object.

get_value(obj)

Return the value of the attribute.

Parameters:

NameTypeDescriptionDefault
objAnyNo description available-

get_context(obj, attr, value, context)

Return any additional template context used to render the attribute value.

Parameters:

NameTypeDescriptionDefault
objAnyNo description available-
attrAnyNo description available-
valueAnyThe value of the attribute on the object context (dict): The panel template context-
contextAnyNo description available-

AddressAttr

Bases: MapURLMixin, ObjectAttribute

A physical or mailing address.

ArrayAttr

Bases: TextAttr

An attribute comprising an array of values, rendered as a comma-separated list. If specified, format_string is applied to each item individually. Null and empty arrays are treated as equivalent: both render as the placeholder.

BooleanAttr

Bases: ObjectAttribute

A boolean attribute.

ChoiceAttr

Bases: ObjectAttribute

A selection from a set of choices. The class calls get_FOO_display() on the terminal object resolved by the accessor to retrieve the human-friendly choice label. For example, accessor="interface.type" will call interface.get_type_display(). If a get_FOO_color() method exists on that object, it will be used to render a background color for the attribute value.

ColorAttr

Bases: ObjectAttribute

An RGB color value.

DateTimeAttr

Bases: ObjectAttribute

A date or datetime attribute.

GenericForeignKeyAttr

Bases: ObjectAttribute

An attribute representing a related generic relation object. This attribute is similar to RelatedObjectAttr but uses the ContentType of the related object to be displayed alongside the value.

GPSCoordinatesAttr

Bases: MapURLMixin, ObjectAttribute

A GPS coordinates pair comprising latitude and longitude values.

ImageAttr

Bases: ObjectAttribute

An attribute representing an image field on the model. Displays the uploaded image.

NestedObjectAttr

Bases: ObjectAttribute

An attribute representing a related nested object. Similar to RelatedObjectAttr, but includes the ancestors of the related object in the rendered output.

NumericAttr

Bases: ObjectAttribute

An integer or float attribute.

RelatedObjectAttr

Bases: ObjectAttribute

An attribute representing a related object.

RelatedObjectListAttr

Bases: RelatedObjectAttr

An attribute representing a list of related objects. The accessor may resolve to a related manager or queryset.

TemplatedAttr

Bases: ObjectAttribute

Renders an attribute using a custom template.

TextAttr

Bases: ObjectAttribute

A text attribute.

TimezoneAttr

Bases: ObjectAttribute

A timezone value. Includes the numeric offset from UTC.

UtilizationAttr

Bases: ObjectAttribute

Renders the value of an attribute as a utilization graph.