Example: Basic template using Django tags

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

This example shows how to use Django tags to create a basic template with a chart and an events viewer that displays results from a search.


To use this code, save it as an HTML file under an existing app in $SPLUNK_HOME/etc/apps/app_name/django/app_name/templates, then view the page in Splunk. For example, to view mypage.html in mysplunkapp, go to http://<localhost:port>/dj/mysplunkapp/mypage. For more about creating an app, see How to create a Web Framework app using Django Bindings.

{% extends "splunkdj:base_with_app_bar.html" %}

{% load splunkmvc %}

{% block title %}Basic template example (Django){% endblock title %}

{% 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 %}
    <h4>A chart and an events viewer displaying results of a search</h4>
    {% chart id="chart1" managerid="search1" type="bar" %}
    {% eventsviewer id="eviewer1" managerid="search1" %}
{% endblock content%}

{% block managers %}
    {% searchmanager id="search1" 
        search="index=_internal | head 1000 | stats count by sourcetype" 
        preview=True cache=True
{% endblock managers %}