【发布时间】:2014-05-12 17:31:18
【问题描述】:
我正在尝试将 trac wiki markdown 格式呈现为 html 以显示在我的网站上。我尝试关注另一个SO question 'how do i use trac wiki formatting',但code snippet 在我运行它时返回错误。需要注意的是,问题和代码已经有将近 4 年的历史了。知道如何让它工作吗?
在我的 urls.py 中,我只需调用 tracwiki(来自 sn-p)视图。
# urls.py
url(r'^$', 'tracwiki', name='index'),
#views.py
"""
Usage:
{% load tracwiki %}
{{ object.body|tracwiki }}
# Logic from http://groups.google.com/group/trac-dev/msg/479decac43883dc0
"""
from trac.test import EnvironmentStub, Mock, MockPerm
from trac.mimeview import Context
from trac.wiki.formatter import HtmlFormatter
from trac.web.href import Href
from django.utils.safestring import mark_safe
from django import template
register = template.Library()
env = EnvironmentStub()
req = Mock(href=Href('/'), abs_href=Href('http://www.example.com/'),
authname='anonymous', perm=MockPerm(), args={})
context = Context.from_request(req, 'wiki')
@register.filter
def tracwiki(s):
return mark_safe(HtmlFormatter(env, context, s).generate())
这是返回的错误:
[01/Apr/2014 18:40:53] "GET / HTTP/1.1" 500 60948
AttributeError at /
'SafeText' object has no attribute 'get'
Request Method: GET
Request URL: http://xxx.xxx.xxx.xxx/
Django Version: 1.5.5
Exception Type: AttributeError
Exception Value:
'SafeText' object has no attribute 'get'
Exception Location: /mysite/local/lib/python2.7/site-packages/django/middleware/clickjacking.py in process_response, line 30
Python Executable: /Envs/mysite/bin/python
Python Version: 2.7.5
【问题讨论】:
标签: python django django-templates trac wiki-markup