All Apps and Add-ons

Custom template tag - ImportError

cguimezanes
Explorer

Hello,

I'm creating a custom template tag with this tutorial: http://dev.splunk.com/view/SP-CAAAERA to create a "state manager". The final result will be a big green "check" icon (ex: http://t0.gstatic.com/images?q=tbn:ANd9GcRbWqg58C_4e1kCoxBv_YtCgWb7ZvaQs9Qa5ga4enKH7vW0ONieAIBt5TMM) or a big red cross + A date under

So, to be simple I decide to set:
app_name as "check"
template tag name as "check"

I create check.py:

from django import template
from splunkdj.templatetags.tagutils import component_context
register = template.Library()
@register.inclusion_tag('splunkdj:components/component.html', takes_context=True)
def check(context, id, *args, **kwargs):       # The template tag
    return component_context(
        context,
        "check",                           # The custom view's CSS class name
        id,
        "view",
        "check/check",             # Path to the JavaScript class/file for the view
        kwargs
    )

Check.js:

// Custom view tutorial
define(function(require, exports, module) {
    // Load requirements
    var _ = require('underscore');
    var mvc = require('splunkjs/mvc');
    var SimpleSplunkView = require('splunkjs/mvc/simplesplunkview');

    // Define the custom view class
    var CheckView = SimpleSplunkView.extend({
        className: "check",

        // Override the render function to make the view do something
        // In this example: print to the page and to the console
        render: function() {

            // Print to the page
            this.$el.html("Hello, world!");

            // Print to the console
            console.log("Hello, world!");

            return this;
        }
    });
    return CheckView;
});

And check.html

{% extends 'splunkdj:base_with_account_bar.html' %}

{% load splunkmvc %}

{% load check %}

{% block title %}{{your_app_name}}My Custom View{% endblock title %}

{% block content %}
    <h3>Custom View</h3>
    {% check id="check1" %}
{% endblock content %}

But when I access to : http://localhost:8000/dj/check/check I get:

Traceback (most recent call last):
  File "C:\Program Files\Splunk\Python-2.7\Lib\site-packages\cherrypy\wsgiserver\__init__.py", line 1237, in communicate
    req.respond()
  File "C:\Program Files\Splunk\Python-2.7\Lib\site-packages\cherrypy\wsgiserver\__init__.py", line 554, in respond
    self._respond()
  File "C:\Program Files\Splunk\Python-2.7\Lib\site-packages\cherrypy\wsgiserver\__init__.py", line 566, in _respond
    response = self.wsgi_app(self.environ, self.start_response)
  File "C:\Program Files\Splunk\Python-2.7\Lib\site-packages\cherrypy\_cptree.py", line 239, in __call__
    return app(environ, start_response)
  File "C:\Program Files\Splunk\Python-2.7\Lib\site-packages\django\core\handlers\wsgi.py", line 255, in __call__
    response = self.get_response(request)
  File "C:\Program Files\Splunk\Python-2.7\Lib\site-packages\django\core\handlers\base.py", line 178, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "C:\Program Files\Splunk\etc/apps/framework\server\splunkdj\management\commands\runwsgiserver.py", line 189, in handle_uncaught_exception
    return super(LoggingWSGIHandler, self).handle_uncaught_exception(request, resolver, exc_info, *args, **kwargs)
  File "C:\Program Files\Splunk\Python-2.7\Lib\site-packages\django\core\handlers\base.py", line 220, in handle_uncaught_exception
    if resolver.urlconf_module is None:
  File "C:\Program Files\Splunk\Python-2.7\Lib\site-packages\django\core\urlresolvers.py", line 342, in urlconf_module
    self._urlconf_module = import_module(self.urlconf_name)
  File "C:\Program Files\Splunk\Python-2.7\Lib\site-packages\django\utils\importlib.py", line 35, in import_module
    __import__(name)
  File "C:\Program Files\Splunk\etc/apps/framework\server\urls.py", line 129, in <module>
    jsurls.create_javascript_urlpatterns()
  File "C:\Program Files\Splunk\etc/apps/framework\server\splunkdj\utility\jsurls.py", line 78, in create_javascript_urlpatterns
    tmpl = loader.get_template('splunkdj:jsurls.html')
  File "C:\Program Files\Splunk\Python-2.7\Lib\site-packages\django\template\loader.py", line 146, in get_template
    template, origin = find_template(template_name)
  File "C:\Program Files\Splunk\Python-2.7\Lib\site-packages\django\template\loader.py", line 129, in find_template
    loader = find_template_loader(loader_name)
  File "C:\Program Files\Splunk\Python-2.7\Lib\site-packages\django\template\loader.py", line 96, in find_template_loader
    mod = import_module(module)
  File "C:\Program Files\Splunk\Python-2.7\Lib\site-packages\django\utils\importlib.py", line 35, in import_module
    __import__(name)
  File "C:\Program Files\Splunk\etc/apps/framework\server\splunkdj\loaders\template_loader.py", line 8, in <module>
    from django.template.loaders.app_directories import (
  File "C:\Program Files\Splunk\Python-2.7\Lib\site-packages\django\template\loaders\app_directories.py", line 25, in <module>
    raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))
ImproperlyConfigured: ImportError check: No module named check

Do you why did I get this error?

Regards,

0 Karma
1 Solution

cguimezanes
Explorer

OK, my bad the answer was to create a splunk app with CLI not with splunk Web

@See http://dev.splunk.com/view/SP-CAAAEUC

View solution in original post

0 Karma

cguimezanes
Explorer

OK, my bad the answer was to create a splunk app with CLI not with splunk Web

@See http://dev.splunk.com/view/SP-CAAAEUC

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...