0

我正在尝试设置django-sitetree以与django -postman 一起使用,但我运气不佳。

大多数页面都可以正常工作,但我似乎无法弄清楚如何映射 postman_view url 才能正常工作。这是我到目前为止所拥有的。也许有人可以帮助我一点?

站点树.py

from sitetree.utils import tree, item

sitetrees = (
    tree('postman', items=[
        item('Messages', '/messages/', url_as_pattern=False, access_guest=False, access_loggedin=True, children=[
            item('Compose', 'postman_write', access_guest=False, access_loggedin=True),
            item('Inbox', 'postman_inbox', access_guest=False, access_loggedin=True),
            item('View', 'postman_view message.id', access_guest=False, access_loggedin=True, in_menu=False, in_sitetree=False)
        ])
    ])
)

邮递员 urls.py 摘录

urlpatterns = patterns('',                                                      
    url(r'^inbox/(?:(?P<option>'+OPTIONS+')/)?$', InboxView.as_view(), name='postman_inbox'),
    url(r'^sent/(?:(?P<option>'+OPTIONS+')/)?$', SentView.as_view(), name='postman_sent'),
    url(r'^archives/(?:(?P<option>'+OPTIONS+')/)?$', ArchivesView.as_view(), name='postman_archives'),
    url(r'^trash/(?:(?P<option>'+OPTIONS+')/)?$', TrashView.as_view(), name='postman_trash'),
    url(r'^write/(?:(?P<recipients>[^/#]+)/)?$', WriteView.as_view(), name='postman_write'),
    url(r'^reply/(?P<message_id>[\d]+)/$', ReplyView.as_view(), name='postman_reply'),
    url(r'^view/(?P<message_id>[\d]+)/$', MessageView.as_view(), name='postman_view'),
    url(r'^view/t/(?P<thread_id>[\d]+)/$', ConversationView.as_view(), name='postman_view_conversation'),
    url(r'^archive/$', ArchiveView.as_view(), name='postman_archive'),          
    url(r'^delete/$', DeleteView.as_view(), name='postman_delete'),             
    url(r'^undelete/$', UndeleteView.as_view(), name='postman_undelete'),          
    (r'^$', RedirectView.as_view(url='inbox/')),                                
)

两者都postman_write可以postman_inbox正常工作,但是当我访问时postman_view出现此错误:

SiteTreeError at /messages/view/2/

Unable to resolve current sitetree item to get a `title_resolved` for current page. Check whether there is an appropriate sitetree item defined for current URL.
4

1 回答 1

0

感谢空闲标志为我指明了正确的方向。

事实证明 postman/view.html 模板没有一个名为 message 的变量,就像我假设的那样。有一个名为 的消息数组pm_messages。所以更正后的 sitetrees.py 是:

sitetrees = (
    tree('postman', items=[
        item('Messages', '/messages/', url_as_pattern=False, access_guest=False, access_loggedin=True, children=[
            item('Compose', 'postman_write', access_guest=False, access_loggedin=True),
            item('Inbox', 'postman_inbox', access_guest=False, access_loggedin=True),
            item('View', 'postman_view pm_messages.0.id', access_guest=False, access_loggedin=True, in_menu=False, in_sitetree=False)
        ])
    ])
)
于 2014-06-28T19:09:17.027 回答