Hi,

The plans are to use classytags on the website at work and I'm going 
through the documentation and running some experimental code as I go. This 
is being run on with classtags 0.8.0, python 3.5.2, and django 1.10.3.

I've written some templates and using classy tags, written an inclusion tag 
that works as expected. I then add a block tag, called 'Jimblock' and the 
browser cannot find it. In the browser, I get the error message in the 
included file, 'browser_error_msg.txt

The last part of the error message is: 

Exception Type: TemplateSyntaxError at /Ttags/classHello/
> Exception Value: Invalid block tag on line 20: 'Jimblock'. Did you forget 
> to register or load this tag?
>

I would expect the browser to find 'Jimblock' because it found 'Jinclusion' 
before I add 'Jimblock'. Both are defined in the same file, 
'customClassTemplateTags.py', which is attached. The template, 
'classTemplateTags.html' which references 'Jinclusion' and 'Jimblock' is 
also attached.

Directory structure is:

    .../testDjangoProject
             |
             ------------->  utilTemplateTags
                                          |
                                          --------------> templates
                                          |                     |
                                          |                     
-------------->  utilTemplateTags (contains: classTemplateTags.html)
                                          |
                                          ---------------> templatetags 
(contains: customClassTemplateTags.py)

My settings.py file has the following entry:

TEMPLATES = [
>     {
>         'BACKEND': 'django.template.backends.django.DjangoTemplates',
>         'DIRS': [
>                                         os.path.join(BASE_DIR, 
> 'templates'),            ### This is the base directory for templates
>                                         
> os.path.join(BASE_DIR,"polls/templates/polls"),
>                                         
> os.path.join(BASE_DIR,"utilTemplateTags/templates"),
>                                         
> os.path.join(BASE_DIR,"utilTemplateTags/templates/utilTemplateTags"),
>                 ],
>         'APP_DIRS': True,
>                ....
>       }
>

I believe this entry for TEMPLATES is correct. Like I said previously, 
'Jinclusion' is being found, so I expect 'Jimblock' to also be found.

Can anyone help with suggestions?

Jim Anderson 




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/95730de2-e1da-4784-b480-ff561fabaf58%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Environment:


Request Method: GET
Request URL: http://localhost:8000/Ttags/classHello/

Django Version: 1.10.3
Python Version: 3.5.2
Installed Applications:
['django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'polls.apps.PollsConfig',
 'accounts',
 'myUtilsConfig.apps.MyUtilsConfig',
 'utilTemplateTags.apps.UtiltemplatetagsConfig']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware']


Template error:
In template 
/home/jja/testDjangoProject/utilTemplateTags/templates/utilTemplateTags/classTemplateTags.html,
 error at line 20
   Invalid block tag on line 20: 'Jimblock'. Did you forget to register or load 
this tag?   10 :         <p><b>{ % hello "classytags" % }</b>: Outputs <b>{% 
hello "classytags" %}</b></p>
   11 :         <p>{ % hello as myvar % }: Outputs nothing but stores hello 
world into the template variable <b>myvar</b>.</p>
   12 :         <p>{ % hello "my friend" as othervar % }: Outputs nothing but 
stores hello <b>'my friend'</b> into the template variable <b>othervar</b>.</p>
   13 :     </div>
   14 :     <div>
   15 :         <p> {% dummy %} </p>
   16 :         <p> {% dummy as jja %} </p>
   17 :         <p>jja: {{ jja }} </p>
   18 :     </div>
   19 : {% endblock %}
   20 :      {% Jimblock "jim" %} 
   21 :         <div>
   22 :             <p>Example inclusion tag</p>
   23 :             <p>{% jinclusion %}</p>
   24 :         </div>
   25 :     {% endblock %}
   26 : 

Traceback:

File "/home/jja/testenv3.5/lib/python3.5/site-packages/django/template/base.py" 
in parse
  510.                     compile_func = self.tags[command]

During handling of the above exception ('Jimblock'), another exception occurred:

File 
"/home/jja/testenv3.5/lib/python3.5/site-packages/django/core/handlers/exception.py"
 in inner
  39.             response = get_response(request)

File 
"/home/jja/testenv3.5/lib/python3.5/site-packages/django/core/handlers/base.py" 
in _legacy_get_response
  249.             response = self._get_response(request)

File 
"/home/jja/testenv3.5/lib/python3.5/site-packages/django/core/handlers/base.py" 
in _get_response
  187.                 response = self.process_exception_by_middleware(e, 
request)

File 
"/home/jja/testenv3.5/lib/python3.5/site-packages/django/core/handlers/base.py" 
in _get_response
  185.                 response = wrapped_callback(request, *callback_args, 
**callback_kwargs)

File 
"/home/jja/testenv3.5/lib/python3.5/site-packages/django/views/generic/base.py" 
in view
  68.             return self.dispatch(request, *args, **kwargs)

File 
"/home/jja/testenv3.5/lib/python3.5/site-packages/django/views/generic/base.py" 
in dispatch
  88.         return handler(request, *args, **kwargs)

File "/home/jja/testDjangoProject/utilTemplateTags/views.py" in get
  62.         return render_to_response(self.template_name)

File "/home/jja/testenv3.5/lib/python3.5/site-packages/django/shortcuts.py" in 
render_to_response
  21.     content = loader.render_to_string(template_name, context, using=using)

File 
"/home/jja/testenv3.5/lib/python3.5/site-packages/django/template/loader.py" in 
render_to_string
  67.         template = get_template(template_name, using=using)

File 
"/home/jja/testenv3.5/lib/python3.5/site-packages/django/template/loader.py" in 
get_template
  21.             return engine.get_template(template_name)

File 
"/home/jja/testenv3.5/lib/python3.5/site-packages/django/template/backends/django.py"
 in get_template
  39.             return Template(self.engine.get_template(template_name), self)

File 
"/home/jja/testenv3.5/lib/python3.5/site-packages/django/template/engine.py" in 
get_template
  160.         template, origin = self.find_template(template_name)

File 
"/home/jja/testenv3.5/lib/python3.5/site-packages/django/template/engine.py" in 
find_template
  134.                         name, template_dirs=dirs, skip=skip,

File 
"/home/jja/testenv3.5/lib/python3.5/site-packages/django/template/loaders/base.py"
 in get_template
  44.                     contents, origin, origin.template_name, self.engine,

File "/home/jja/testenv3.5/lib/python3.5/site-packages/django/template/base.py" 
in __init__
  191.         self.nodelist = self.compile_nodelist()

File "/home/jja/testenv3.5/lib/python3.5/site-packages/django/template/base.py" 
in compile_nodelist
  233.             return parser.parse()

File "/home/jja/testenv3.5/lib/python3.5/site-packages/django/template/base.py" 
in parse
  518.                     raise self.error(token, e)

File "/home/jja/testenv3.5/lib/python3.5/site-packages/django/template/base.py" 
in parse
  516.                     compiled_result = compile_func(self, token)

File 
"/home/jja/testenv3.5/lib/python3.5/site-packages/django/template/loader_tags.py"
 in do_extends
  299.     nodelist = parser.parse()

File "/home/jja/testenv3.5/lib/python3.5/site-packages/django/template/base.py" 
in parse
  512.                     self.invalid_block_tag(token, command, parse_until)

File "/home/jja/testenv3.5/lib/python3.5/site-packages/django/template/base.py" 
in invalid_block_tag
  574.             "or load this tag?" % (token.lineno, command)

Exception Type: TemplateSyntaxError at /Ttags/classHello/
Exception Value: Invalid block tag on line 20: 'Jimblock'. Did you forget to 
register or load this tag?

from classytags.core import Options
from classytags.core import Tag
from classytags.helpers import AsTag
from classytags.arguments import Argument
from django import template
from classytags.blocks import BlockDefinition
from classytags.blocks import VariableBlockName

register = template.Library()

class Hello(AsTag):
    options = Options(
        Argument('name', required=False, default='world'),
        'as',
        Argument('varname', required=False, resolve=False)
    )

    def get_value(self, context, name):
        return 'hello %s' % name

register.tag(Hello)

from classytags.core import Options
from classytags.arguments import Argument
from classytags.helpers import AsTag
from django import template


class Dummy(AsTag):
    options = Options(
        'as',
        Argument('varname', resolve=False, required=False),
    )

    def get_value(self, context):
        return 'dummy'

register.tag(Dummy)

from classytags.helpers import InclusionTag

class Jinclusion(InclusionTag):
    template = 'included.html'

    def get_context(self, context):
        return {'info': 'jInclusion'}

register.tag(Jinclusion)

class Jimblock(Tag):
    options = Options(
        Argument('name', resolve=False),
        blocks=[ BlockDefinition('nodelist', VariableBlockName('endblock %(value)s', 'name'), 'endblock') ]
    )

register.tag(Jimblock)
{% extends 'testDjangoProject/base.html' %} {% load customClassTemplateTags %} {% block content %}

{ % hello % }: Outputs {% hello %}

{ % hello "" % }: Outputs {% hello "" %}

{ % hello "classytags" % }: Outputs {% hello "classytags" %}

{ % hello as myvar % }: Outputs nothing but stores hello world into the template variable myvar.

{ % hello "my friend" as othervar % }: Outputs nothing but stores hello 'my friend' into the template variable othervar.

{% dummy %}

{% dummy as jja %}

jja: {{ jja }}

{% endblock %} {% Jimblock "jim" %}

Example inclusion tag

{% jinclusion %}

{% endblock %}

Reply via email to