Closed bhekidaweti closed 2 months ago
This is most certainly a user error, but unfortunately, you have not provided enough information for anyone to help.
markdown_extras' is not a registered tag library.
This makes me think you've somehow configured something wrong in your app, which may not even be Python Markdown related.
In order for someone to be able to help, please provide a minimal, reproducible example so that we can get some idea of what the real question really is.
This is my code both in local server and deployment server i have installed markdown using pip install and it appears under pip list in in both development and deployment.
html file :
{% extends "quiz/layout.html" %}
{% load markdown_extras %}
{% block body %}
<h1>{{ post.title }}</h1>
<p>By {{ post.author.username }} on {{ post.created_at }}</p>
{% if post.image %}
<img src="{{ post.image.url }}" alt="{{ post.title }}">
{% endif %}
<div>{{ post.content|convert_markdown|safe }}</div>
<a href="{% url 'post_list' %}">Back to Blog</a>
{% endblock %}
markdown_extras.py file in the templatestags folder( I have also created en empty init.py file in this folder . )
import markdown
from django import template
from django.template.defaultfilters import stringfilter
from django.utils.safestring import mark_safe
register = template.Library()
@register.filter
@stringfilter
def convert_markdown(value):
return markdown.markdown(value, extensions=['markdown.extensions.fenced_code'])
This the error I get (I have set the debug mode to true just to show this error)
TemplateSyntaxError at /1/
'markdown_extras' is not a registered tag library. Must be one of: admin_list admin_modify admin_urls cache i18n l10n log static tzRequest Method: | GET -- | --5.0.3 TemplateSyntaxError 'markdown_extras' is not a registered tag library. Must be one of: admin_list admin_modify admin_urls cache i18n l10n log static tz /home/ubuntu/env/lib/python3.10/site-packages/django/template/defaulttags.py, line 1036, in find_library blog.views.post_detail /home/ubuntu/env/bin/python3 3.10.12 ['/home/ubuntu/capstone', '/home/ubuntu/env/bin', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/home/ubuntu/env/lib/python3.10/site-packages'] Sun, 02 Jun 2024 10:11:49 +0000
TemplateSyntaxError at /1/ 'markdown_extras' is not a registered tag library. Must be one of: admin_list admin_modify admin_urls cache i18n l10n log static tz Request Method: GETYou’re seeing this error because you have
DEBUG = True
in your Django settings file. Change that toFalse
, and Django will display a standard page generated by the handler for this status code.Django Version: 5.0.3 Exception Type: TemplateSyntaxError Exception Value:
'markdown_extras' is not a registered tag library. Must be one of: admin_list admin_modify admin_urls cache i18n l10n log static tz Exception Location: /home/ubuntu/env/lib/python3.10/site-packages/django/template/defaulttags.py, line 1036, in find_library Raised during: blog.views.post_detail Python Executable: /home/ubuntu/env/bin/python3 Python Version: 3.10.12 Python Path:
['/home/ubuntu/capstone', '/home/ubuntu/env/bin', '/usr/lib/python310.zip', '/usr/lib/python3.10', '/usr/lib/python3.10/lib-dynload', '/home/ubuntu/env/lib/python3.10/site-packages'] Server time: Sun, 02 Jun 2024 10:11:49 +0000 Error during template rendering In template /home/ubuntu/capstone/blog/templates/blog/post_detail.html, error at line 3'markdown_extras' is not a registered tag library. Must be one of: admin_list admin_modify admin_urls cache i18n l10n log static tz 1 {% extends "quiz/layout.html" %} 2
3 {% load markdown_extras %} 4
5 {% block body %} 6{{ post.title }}
7By {{ post.author.username }} on {{ post.created_at }}
8 {% if post.image %} 910 {% endif %} 11
{{ post.content|convert_markdown|safe }}12 Back to Blog 13 {% endblock %} Traceback Switch to copy-and-paste view /home/ubuntu/env/lib/python3.10/site-packages/django/template/defaulttags.py, line 1034, in find_library return parser.libraries[name] … Local vars During handling of the above exception ('markdown_extras'), another exception occurred: /home/ubuntu/env/lib/python3.10/site-packages/django/core/handlers/exception.py, line 55, in inner response = get_response(request) … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/core/handlers/base.py, line 197, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) … Local vars /home/ubuntu/capstone/blog/views.py, line 12, in post_detail return render(request, 'blog/post_detail.html', {'post': post}) … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/shortcuts.py, line 25, in render content = loader.render_to_string(template_name, context, request, using=using) … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/template/loader.py, line 61, in render_to_string template = get_template(template_name, using=using) … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/template/loader.py, line 15, in get_template return engine.get_template(template_name) … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/template/backends/django.py, line 33, in get_template return Template(self.engine.get_template(template_name), self) … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/template/engine.py, line 177, in get_template template, origin = self.find_template(template_name) … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/template/engine.py, line 159, in find_template template = loader.get_template(name, skip=skip) … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/template/loaders/cached.py, line 57, in get_template template = super().get_template(template_name, skip) … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/template/loaders/base.py, line 28, in get_template return Template( … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/template/base.py, line 154, in init self.nodelist = self.compile_nodelist() … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/template/base.py, line 196, in compile_nodelist return parser.parse() … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/template/base.py, line 510, in parse raise self.error(token, e) … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/template/base.py, line 508, in parse compiled_result = compile_func(self, token) … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/template/loader_tags.py, line 295, in do_extends nodelist = parser.parse() … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/template/base.py, line 510, in parse raise self.error(token, e) … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/template/base.py, line 508, in parse compiled_result = compile_func(self, token) … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/template/defaulttags.py, line 1096, in load lib = find_library(parser, name) … Local vars /home/ubuntu/env/lib/python3.10/site-packages/django/template/defaulttags.py, line 1036, in find_library raise TemplateSyntaxError( … Local vars
Okay this is what I was looking for. This seems like a question for Django, not Python Markdown.
I thought this was a question about the Markdown "extras" extension, but what you are asking about is how to properly use Django's templating, which is better asked over at the Django repository, not here.
Ok thanks Isaac
Maybe the problem is that you named the folder templatestags
, it should be templatetags
without the s
in the middle.
Maybe the problem is that you named the folder
templatestags
, it should betemplatetags
without thes
in the middle.
Thanks I will try your suggestion and rename the folder
Maybe the problem is that you named the folder
templatestags
, it should betemplatetags
without thes
in the middle.
Wow thanks . Your suggestion fixed the problem I am so happy :)
Markdown works well in local development but not in deployment. I get the ff error in deployment:
markdown_extras' is not a registered tag library. Must be one of: admin_list admin_modify admin_urls cache i18n l10n log static tz
My django app is deployed on aws and im using nginx .Your help is much appriciated