banner



Expected 'endblock'. Did You Forget To Register Or Load This Tag?

I've created a custom tag that I want to employ, simply Django can't seem to notice it. My templatetags directory is set up upwards like this:

pygmentize.py

            from pygments import highlight from pygments.lexers import get_lexer_by_name from django import template from pygments.formatters.other import NullFormatter  annals = template.Library()  @register.tag(name='code') def do_code(parser,token):     code = token.split_contents()[-1]     nodelist = parser.parse(('endcode',))     parser.delete_first_token()     return CodeNode(code,nodelist)  form CodeNode(template.Node):     def __init__(self,lang,code):         cocky.lang = lang         cocky.nodelist = lawmaking      def render(self,context):         code = cocky.nodelist.render(context)         lexer = get_lexer_by_name('python')         return highlight(code,lexer,NullFormatter())                      

I am trying to use this tag to render code in gameprofile.html.

gameprofile.html

            (% load pygmentize %} {% block content %}     <title>{% cake title %} | {{ game.championship }}{% endblock %}</title>     <div id="gamecodecontainer">         {% code %}             {{game.code}}         {% endcode %}     </div> {% endblock content %}                      

When I navigate to gameprofile.html, I get an error:

Invalid block tag on line 23: 'code', expected 'endblock'. Did you forget to register or load this tag?

This question is tagged with python django django-templates pygments templatetags

~ Asked on 2016-01-28 06:26:05

The mistake is in this line: (% load pygmentize %}, an invalid tag. Alter information technology to {% load pygmentize %}

~ Answered on 2017-01-24 06:36:35

            {% load static %} <img src="{% static "my_app/case.jpg" %}" alt="My prototype">                      

in your templates, use the static template tag to build the URL for the given relative path using the configured STATICFILES_STORAGE.

~ Answered on 2019-06-29 09:56:17

For Django 2.2 upwards to three, you have to load staticfiles in html template beginning earlier use static keyword

            {% load staticfiles %} <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">                      

For other versions use static

            {% load static %} <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">                      

Likewise yous accept to check that you defined STATIC_URL in setting.py

At final, make sure the static files exist in the defined folder

~ Answered on 2019-09-17 eighteen:42:58

did you try this

            {% load games_tags %}                      

at the top instead of pygmentize?

~ Answered on 2016-03-17 17:06:40

            {% load static %}                      

Delight add together this template tag on tiptop of the HTML or base of operations HTML file

~ Answered on 2019-05-25 x:56:03

I had the same problem, hither's how I solved it. Following the first section of this very excellent Django tutorial, I did the following:

  1. Create a new Django app by executing: python manage.py startapp new_app
  2. Edit the settings.py file, adding the following to the list of INSTALLED_APPS: 'new_app',
  3. Add a new module to the new_app package named new_app_tags.
  4. In a Django HTML template, add the post-obit to the top of the file, but after {% extends 'base_template_name.html' %}: {% load new_app_tags %}
  5. In the new_app_tags module file, create a custom template tag (meet below).
  6. In the aforementioned Django HTML template, from step 4 above, use your shiney new custom tag like then: {% multiply_by_two | "5.0" %}
  7. Celebrate!

Instance from step 5 above:

            from django import template  register = template.Library()  @register.simple_tag def multiply_by_two(value):     return bladder(value) * ii.0                      

~ Answered on 2018-02-07 04:28:33

In gameprofile.html please change the tag {% endblock content %} to {% endblock %} and then it works otherwise django will non load the endblock and give error.

~ Answered on 2018-09-24 12:44:48

The app that contains the custom tags must be in INSTALLED_APPS. So Are you certain that your directory is in INSTALLED_APPS ?

From the documentation:

The app that contains the custom tags must exist in INSTALLED_APPS in order for the {% load %} tag to work. This is a security characteristic: Information technology allows you to host Python code for many template libraries on a single host machine without enabling access to all of them for every Django installation.

~ Answered on 2016-01-28 07:33:42

Y'all need to alter:

            {% endblock content %}                      

to

            {% endblock %}                      

~ Answered on 2018-04-x 02:53:41

Expected 'endblock'. Did You Forget To Register Or Load This Tag?,

Source: https://syntaxfix.com/question/3847/django-did-you-forget-to-register-or-load-this-tag

Posted by: colettisuppen.blogspot.com

0 Response to "Expected 'endblock'. Did You Forget To Register Or Load This Tag?"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel