我正在尝试将trac wiki标记格式呈现为html,以便在我的网站上显示。我试着跟踪另一个SO question 'how do i use trac wiki formatting',但是code snippet在运行时返回一个错误。需要注意的是,这个问题和代码已经有将近4年的历史了。你知道我怎样才能让它工作吗?
在my urls.py中,我只需调用tracwiki
(来自snippet)视图。
#url.py
url(r'^$', 'tracwiki', name='index'),
视图.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
目前没有回答
相关问题 更多 >
编程相关推荐