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!

Splunk Observability Cloud | Unified Identity - Now Available for Existing Splunk ...

Raise your hand if you’ve already forgotten your username or password when logging into an account. (We can’t ...

Index This | How many sides does a circle have?

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

Registration for Splunk University is Now Open!

Are you ready for an adventure in learning?   Brace yourselves because Splunk University is back, and it's ...