私のウェブサイトに表示するために、trac wiki マークダウン形式を html としてレンダリングしようとしています。この他のSO の質問 'trac wiki の書式設定を使用するにはどうすればよいですか'に従ってみましたが、コード スニペットを実行するとエラーが返されます。質問とコードは 4 年近く前のものであることに注意してください。どうすればこれを機能させることができますか?
私の urls.py では、tracwiki
(スニペットから) ビューを呼び出すだけです。
#urls.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