Django Nonrel 中的 {% markdown %} 和 {% Textile %} 过滤器出错

发布于 2024-12-15 19:15:19 字数 1498 浏览 1 评论 0原文

我在 Django Nonrel 中使用 Markdown 时遇到问题。我遵循了这个说明(添加了'django.contrib.markup'INSTALLED_APPS,在模板中包含 {% load markup %} 并在安装 python-markdown 后使用 |markdown 过滤器),但我得到了下列的错误:

Error in {% markdown %} filter: The Python markdown library isn't installed.

在这一行中:

/path/to/project/django/contrib/markup/templatetags/markup.py in markdown
    they will be silently ignored.
    """
    try:
        import markdown
    except ImportError:
        if settings.DEBUG:
            raise template.TemplateSyntaxError("Error in {% markdown %} filter: The Python markdown library isn't installed.") ...
        return force_unicode(value)
    else:
        # markdown.version was first added in 1.6b. The only version of markdown
        # to fully support extensions before 1.6b was the shortlived 1.6a.
        if hasattr(markdown, 'version'):
            extensions = [e for e in arg.split(",") if e]

很明显 import markdown 导致了问题,但是当我运行时:

$ python manage.py shell
>>> import elementtree
>>> import markdown

一切正常。

运行 Markdown 2.0.3、Python 2.7 和最新版本的 Django Nonrel。

更新:我安装了纺织品,但它不起作用。它会产生相同的错误。

更新 2:这是与 Django Nonrel 相关的问题。我采用了一个较旧的 Django 项目 (1.3.1),并且按预期工作。

有想法吗?

谢谢!

I'm having trouble using Markdown in Django Nonrel. I followed this instructions (added 'django.contrib.markup' to INSTALLED_APPS, include {% load markup %} in the template and use |markdown filter after installing python-markdown) but I get the following error:

Error in {% markdown %} filter: The Python markdown library isn't installed.

In this line:

/path/to/project/django/contrib/markup/templatetags/markup.py in markdown
    they will be silently ignored.
    """
    try:
        import markdown
    except ImportError:
        if settings.DEBUG:
            raise template.TemplateSyntaxError("Error in {% markdown %} filter: The Python markdown library isn't installed.") ...
        return force_unicode(value)
    else:
        # markdown.version was first added in 1.6b. The only version of markdown
        # to fully support extensions before 1.6b was the shortlived 1.6a.
        if hasattr(markdown, 'version'):
            extensions = [e for e in arg.split(",") if e]

It seems obvious that import markdown is causing the problem but when I run:

$ python manage.py shell
>>> import elementtree
>>> import markdown

everthing works alright.

Running Markdown 2.0.3, Python 2.7 and latest version of Django Nonrel.

UPDATE: I installed textile and it doesn't work. It produces the same error.

UPDATE 2: This is an issue related with Django Nonrel. I took an older Django project (1.3.1), and works as expected.

Ideas?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沧桑㈠ 2024-12-22 19:15:19

好吧,新手错误。

结果 Django Nonrel 找不到 markdown,因为由于某种原因,它没有安装在它正在寻找的 python 路径中。在本例中,markdown 安装在 /usr/lib/pymodules/python2.7 中,而不是 /usr/local/lib/python2.7/dist-packages/ 或其他一些平常的地方。所以我将 markdown 文件夹复制到 python 路径列出的位置,错误就消失了。

Alright, newbie mistake.

Turns out that Django Nonrel couldn't find markdown because for some reason, it wasn't installed in a python path it was looking for. In this case, markdown was installed in /usr/lib/pymodules/python2.7 instead of /usr/local/lib/python2.7/dist-packages/ or some other usual place. So I copied the markdown folder to a place listed by python path, and the error went away.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文