简体   繁体   English

如何在模板标签中实现 markdown2? 获取 TemplateSyntaxError 'md2' 不是已注册的标记库

[英]How to implement markdown2 in the template tags? Getting TemplateSyntaxError 'md2' is not a registered tag library

I followed instructions at this source for getting markdown2 to work in the template tags.我按照这个来源的说明让 markdown2 在模板标签中工作。 The code is below.代码如下。

settings.py : settings.py

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'wikiencyc',
    'markdown2',
]

Note: I tried using the originally suggested 'django_markdown2' above but the Django server would not start and give a chain of exceptions originating with the following error:注意:我尝试使用上面最初建议的'django_markdown2' ,但 Django 服务器无法启动并给出一系列异常,并出现以下错误:

'<frozen importlib._bootstrap>'
from line 200 in Python38-32/lib/pathlib.py

With 'markdown2' instead of 'django_markdown2' , the server started.使用'markdown2'而不是'django_markdown2' ,服务器启动。

entry_detail.html : entry_detail.html

{% load md2 %}
<h4>{{ entry.subject }} </h4>
<br><br>
<p>
    {{ entry.content|markdown:"safe" }}
</p>

So, I have tried to do everything according to book.所以,我试图按照书做一切。 I also made sure that markdown2.py is in the path.我还确保markdown2.py在路径中。

I am not sure what they mean by putting django_markdown2 in the PYTHONPATH.我不确定将django_markdown2放在 PYTHONPATH 中是什么意思。 Such an environment variable does not exist on my system.我的系统上不存在这样的环境变量。 I tried creating said env variable and putting the value of django_markdown2 , but still no joy.我尝试创建所说的 env 变量并放置django_markdown2的值,但仍然没有乐趣。

I am using Windows 7 as OS, Python version 3.8, and Django version 3.0.8.我使用 Windows 7 作为操作系统、Python 3.8 版和 Django 3.0.8 版。 Below is the output of pip freeze :以下是pip freeze的输出:

asgiref==3.2.10
cachelib==0.1.1
click==7.1.2
Django==3.0.8
Flask==1.1.2
Flask-Session==0.3.2
itsdangerous==1.1.0
Jinja2==2.11.2
markdown2==2.3.9
MarkupSafe==1.1.1
Pillow==7.2.0
psycopg2-binary==2.8.5
pytz==2020.1
SQLAlchemy==1.3.18
sqlparse==0.3.1
Werkzeug==1.0.1

I get the following error.我收到以下错误。

TemplateSyntaxError at /wikiencyc/entry/9
'md2' is not a registered tag library. Must be one of:
admin_list
admin_modify
admin_urls
cache
i18n
l10n
log
static
tz

What am I doing wrong?我究竟做错了什么? Please provide the specifics: which file to edit, what libs to use or import, and exactly what to type, the exact syntax, and where.请提供详细信息:要编辑的文件、要使用或导入的库、要键入的内容、确切的语法和位置。 The devil is in the details.细节决定成败。

I think it is supposed to be我认为它应该是

'django_markdown2',

Instead of代替

'markdown2',

In settings.py在settings.py中

This is the same for Adding it to the path这与将其添加到路径相同

I don't think you've actually installed django-markdown2 : it doesn't appear in your pip freeze output.我认为您实际上没有安装django-markdown2 :它没有出现在您的pip freeze输出中。 It sounds like you've tried to manually download the file and modify your PYTHONPATH , but there should be no need to do that.听起来您已经尝试手动下载文件并修改您的PYTHONPATH ,但应该没有必要这样做。

I hope you are explicitly defining your dependencies, in which case you could add django-markdown2 to your requirements.txt and run pip install -r requirements.txt .我希望您明确定义您的依赖项,在这种情况下,您可以将django-markdown2添加到您的requirements.txt并运行pip install -r requirements.txt If not, please consider starting this practice.如果没有,请考虑开始这种做法。

If you just want to install django-markdown2 in your current environment, run如果您只想在当前环境中安装django-markdown2 ,请运行

pip install django-markdown2

and forget about manually downloading anything or modifying PYTHONPATH .忘记手动下载任何东西或修改PYTHONPATH

Hopefully this is with in a virtual environment.希望这是在虚拟环境中。

Then, once you've installed the library, change your settings.py to include django_markdown2 in your INSTALLED_APPS instead of markdown2 .然后,一旦安装了库,请更改settings.py以在INSTALLED_APPS包含django_markdown2而不是markdown2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在模板标签中导入Markdown2 - Importing Markdown2 in template tag TemplateSyntaxError &#39;apptags&#39; 不是注册的标签库 - TemplateSyntaxError 'apptags' is not a registered tag library Django 1.10 TemplateSyntaxError&#39;future&#39;不是注册的标签库 - Django 1.10 TemplateSyntaxError 'future' is not a registered tag library Django TemplateSyntaxError - 'staticfiles' 不是注册的标签库 - Django TemplateSyntaxError - 'staticfiles' is not a registered tag library django 中的“TemplateSyntaxError at / 'humanize' is not a registered tag library” - “TemplateSyntaxError at / 'humanize' is not a registered tag library” in django /messages/inbox/ 'account_tags' 处的 TemplateSyntaxError 不是已注册的标签库。 必须是以下之一: - TemplateSyntaxError at /messages/inbox/ 'account_tags' is not a registered tag library. Must be one of: django.template.exceptions.TemplateSyntaxError:&#39;static&#39;不是已注册的标记库。 必须是以下之一: - django.template.exceptions.TemplateSyntaxError: 'static' is not a registered tag library. Must be one of: TemplateSyntaxError:“ settings_tags”不是有效的标签库 - TemplateSyntaxError: 'settings_tags' is not a valid tag library /&#39;avatar_tags&#39;处的TemplateSyntaxError不是有效的标签库 - TemplateSyntaxError at / 'avatar_tags' is not a valid tag library Django 3 TemplateSyntaxError: 'css/bootstrap.min.css' 不是注册的标签库 - Django 3 TemplateSyntaxError: 'css/bootstrap.min.css' is not a registered tag library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM