我使用django的当前版本是1.6.3
我写了一段代码
{% load markup %}
在我的blog_list.html
中我得错了
'markup' is not a valid tag library: Template library markup not found, tried django.templatetags.markup,django.contrib.admin.templatetags.markup,django.contrib.staticfiles.templatetags.markup`
所以我检查了文档,然后我找到了方法,然后我添加了django.contrib.markup'到INSTALL_APPS设置。当我运行服务器时我得到了这个:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 280, in execute
translation.activate('en-us')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/translation/__init__.py", line 130, in activate
return _trans.activate(language)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 188, in activate
_active.value = translation(language)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 177, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module
__import__(name)
ImportError: No module named markup
所以我用macports搜索了标记,然后安装了py27-markupsafe。我也无法导入它。我该怎么办?
答案 0 :(得分:4)
如果查看Django Depreciation Timeline,您会注意到以下内容:
django.contrib.markup will be removed following an accelerated deprecation.
这意味着从1.6开始,Django不会自动包含标记。您可以阅读更多相关信息here。
作为替代品,我已成功使用django-markdown-deux
,一旦安装,就会提供模板标记:
{% load markdown_deux_tags %}
{{ myvar|markdown }}
答案 1 :(得分:0)
假设您正在使用旧的Django(在此之前被删除),请将以下内容添加到settings.py中的INSTALLED_APPS:
&#39; django.contrib.markup&#39;
这应该可以解决问题。