How to create a Splunk view using Django Bindings

Django Bindings has been deprecated. For more, see the Deprecation Notice.

The Splunk Web Framework provides a variety of Splunk views you can use to display and interact with searches. Splunk views are defined with tags in the content block of a template. For a list of Splunk views along with their properties, methods, and events, see the Splunk Web Framework Component Reference. The content block also defines the layout of the Splunk views on the page. Views are displayed in the order they are defined on the page.

The example below illustrates how to add three Splunk views―Chart, Timeline, and EventsViewer―to a template. Each view is linked to the same search by setting the view's managerid property to the value of the search manager id property, "search1", as follows:

...
{% block content %}
    {% chart id="chart1" managerid="search1" type="bar" %}
    {% timeline id="timeline1" managerid="search1" %}
    {% eventsviewer id="eviewer1" managerid="search1" %}
{% endblock content%}

{% block managers %}
    {% searchmanager id="search1"
        search="index=_internal | head 1000 | stats count by sourcetype"
        preview=True
        required_field_list="*"
        status_buckets=300 %}
{% endblock managers %}
...

The content block does not contain any formatting, so the Splunk views are just displayed in the order they are defined. This next example shows how you could lay out the page using Splunk's dashboard CSS (the CSS block is included so you can see the necessary style sheet links):

...
{% block css %}
    <link rel="stylesheet" type="text/css" href="{{STATIC_URL}}{{app_name}}/custom.css" />
    <link rel="stylesheet" type="text/css" href="{{STATIC_URL}}splunkjs/css/dashboard.css" />
{% endblock css %}
{% block content %}
<div class="dashboard-body container-fluid main-section-body">
    <div class="row">
        <div class="dashboard-header clearfix">
            <h2>Add views to a template using Django template tags</h2>
        </div>
    </div>
    <!-- Row for the chart -->
    <div class="dashboard-row">
        <div class="dashboard-cell" style="width: 100%;">
            <div class="dashboard-panel">
                <div class="dashboard-element">
                    <div class="panel-head">
                        <h3>Chart</h3>
                    </div>
                    <div class="panel-body">
                        {% chart id="chart1" managerid="search1" type="bar" %}
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Row for the timeline -->
    <div class="dashboard-row">
        <div class="dashboard-cell" style="width: 100%;">
            <div class="dashboard-panel">
                <div class="dashboard-element">
                    <div class="panel-head">
                        <h3>Timeline</h3>
                    </div>
                    <div class="panel-body">
                        {% timeline id="timeline1" managerid="search1" %}
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- Row for the events viewer -->
    <div class="dashboard-row">
        <div class="dashboard-cell" style="width: 100%;">
            <div class="dashboard-panel">
                <div class="dashboard-element">
                    <div class="panel-head">
                        <h3>Events viewer</h3>
                    </div>
                    <div class="panel-body">
                        {% eventsviewer id="eviewer1" managerid="search1" %}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock content%}

{% block managers %}
    {% searchmanager id="search1"
        search="index=_internal | head 1000 | stats count by sourcetype"
        preview=True
        required_field_list="*"
        status_buckets=300 %}
{% endblock managers %}
...

For more about how to use the dashboard styles, see Splunk dashboard styles.

To programmatically set or get view properties or listen for events (such as change or click events), you'll need to use JavaScript and the SplunkJS Stack component of the Web Framework. For more, see How to set view properties using SplunkJS Stack and How to listen for events on views using SplunkJS Stack.