Invalid Block Tag On Line 2: 'static'. Did You Forget To Register Or Load This Tag?
I've created a custom tag that I want to use, but Django can't seem to find it. My templatetags directory is set up up 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 register = template.Library() @register.tag(proper noun='code') def do_code(parser,token): lawmaking = token.split_contents()[-ane] nodelist = parser.parse(('endcode',)) parser.delete_first_token() return CodeNode(code,nodelist) grade CodeNode(template.Node): def __init__(self,lang,code): self.lang = lang self.nodelist = code def render(self,context): code = cocky.nodelist.render(context) lexer = get_lexer_by_name('python') render highlight(code,lexer,NullFormatter()) I am trying to use this tag to return lawmaking in gameprofile.html.
gameprofile.html
(% load pygmentize %} {% block content %} <title>{% block title %} | {{ game.title }}{% endblock %}</title> <div id="gamecodecontainer"> {% code %} {{game.lawmaking}} {% endcode %} </div> {% endblock content %} When I navigate to gameprofile.html, I become an mistake:
Invalid cake tag on line 23: 'code', expected 'endblock'. Did you forget to annals or load this tag?
This question is tagged with python django django-templates pygments templatetags
~ Asked on 2016-01-28 06:26:05
The error is in this line: (% load pygmentize %}, an invalid tag. Alter it to {% load pygmentize %}
~ Answered on 2017-01-24 06:36:35
{% load static %} <img src="{% static "my_app/example.jpg" %}" alt="My image"> in your templates, apply 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.ii up to three, you take to load staticfiles in html template first before utilize static keyword
{% load staticfiles %} <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> For other versions apply static
{% load static %} <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}"> Besides you have to check that you lot divers STATIC_URL in setting.py
At concluding, brand sure the static files be in the divers binder
~ Answered on 2019-09-17 18:42:58
did yous try this
{% load games_tags %} at the top instead of pygmentize?
~ Answered on 2016-03-17 17:06:40
{% load static %} Please add this template tag on top of the HTML or base HTML file
~ Answered on 2019-05-25 x:56:03
I had the same problem, hither's how I solved it. Following the offset section of this very fantabulous Django tutorial, I did the post-obit:
- Create a new Django app by executing:
python manage.py startapp new_app - Edit the
settings.pyfile, adding the post-obit to the list ofINSTALLED_APPS:'new_app', - Add a new module to the
new_appbundle namednew_app_tags. - In a Django HTML template, add the following to the acme of the file, but subsequently
{% extends 'base_template_name.html' %}:{% load new_app_tags %} - In the
new_app_tagsmodule file, create a custom template tag (see below). - In the same Django HTML template, from step 4 above, use your shiney new custom tag like and so:
{% multiply_by_two | "5.0" %} - Gloat!
Example from step five higher up:
from django import template register = template.Library() @annals.simple_tag def multiply_by_two(value): return float(value) * 2.0 ~ Answered on 2018-02-07 04:28:33
In gameprofile.html delight change the tag {% endblock content %} to {% endblock %} then information technology works otherwise django will non load the endblock and give fault.
~ Answered on 2018-09-24 12:44:48
The app that contains the custom tags must exist 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 be in
INSTALLED_APPSin gild for the{% load %}tag to piece of work. This is a security feature: It 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
You need to change:
{% endblock content %} to
{% endblock %} ~ Answered on 2018-04-10 02:53:41
Source: https://syntaxfix.com/question/3847/django-did-you-forget-to-register-or-load-this-tag
Posted by: deweyallonand.blogspot.com

0 Response to "Invalid Block Tag On Line 2: 'static'. Did You Forget To Register Or Load This Tag?"
Post a Comment