Django CMS 用のカスタム アプリを作成していますが、管理者で公開されたエントリを表示しようとすると、次のエラーが発生します。
/admin/cmsplugin_publisher/entry/ の TemplateSyntaxError
レンダリング中に NoReverseMatch をキャッチしました: 引数 '()' とキーワード引数 '{'slug': u'test-german'}' を持つ 'cmsplugin_publisher_entry_detail' のリバースが見つかりません。
メイン アプリケーション urls.py でアプリに URL を指定すると、アプリを動作させることができますが、アプリを必要な URL に固定します。Django CMS を拡張して、追加されたページからアプリが取得されるようにするだけです。
models.py 絶対 URL パターン
@models.permalink
def get_absolute_url(self):
return ('cmsplugin_publisher_entry_detail', (), {
'slug': self.slug})
urls/entries.py
from django.conf.urls.defaults import *
from cmsplugin_publisher.models import Entry
from cmsplugin_publisher.settings import PAGINATION, ALLOW_EMPTY, ALLOW_FUTURE
entry_conf_list = {'queryset': Entry.published.all(), 'paginate_by': PAGINATION,}
entry_conf = {'queryset': Entry.published.all(),
'date_field': 'creation_date',
'allow_empty': ALLOW_EMPTY,
'allow_future': ALLOW_FUTURE,
}
entry_conf_detail = entry_conf.copy()
del entry_conf_detail['allow_empty']
del entry_conf_detail['allow_future']
del entry_conf_detail['date_field']
entry_conf_detail['queryset'] = Entry.objects.all()
urlpatterns = patterns('cmsplugin_publisher.views.entries',
url(r'^$', 'entry_index', entry_conf_list,
name='cmsplugin_publisher_entry_archive_index'),
url(r'^(?P<page>[0-9]+)/$', 'entry_index', entry_conf_list,
name='cmsplugin_publisher_entry_archive_index_paginated'),
)
urlpatterns += patterns('django.views.generic.list_detail',
url(r'^(?P<slug>[-\w]+)/$', 'object_detail', entry_conf_detail,
name='cmsplugin_publisher_entry_detail'),
)
ビュー/エントリ.py
from django.views.generic.list_detail import object_list
from cmsplugin_publisher.models import Entry
from cmsplugin_publisher.views.decorators import update_queryset
entry_index = update_queryset(object_list, Entry.published.all)
ビュー/デコレータ.py
def update_queryset(view, queryset, queryset_parameter='queryset'):
'''Decorator around views based on a queryset passed in parameter which will force the update despite cache
Related to issue http://code.djangoproject.com/ticket/8378'''
def wrap(*args, **kwargs):
'''Regenerate the queryset before passing it to the view.'''
kwargs[queryset_parameter] = queryset()
return view(*args, **kwargs)
return wrap
Django CMS とのアプリ統合については、http: //github.com/divio/django-cms/blob/master/cms/docs/app_integration.txtで説明されています。
アプリケーションで汎用ビューとカスタムのミスを使用しているため、 RequestContext を正しく返していないことが問題のようです。
CMS アプリ拡張 py ファイル:
cms_app.py
from django.utils.translation import ugettext_lazy as _
from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from cmsplugin_publisher.settings import APP_MENUS
class PublisherApp(CMSApp):
name = _('Publisher App Hook')
urls = ['cmsplugin_publisher.urls']
apphook_pool.register(PublisherApp)
任意のポインターを高く評価しました。クラックするのは難しいことが証明されています!