0

我正在为 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})

网址/条目.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)

任何指针表示赞赏,事实证明这是一个难以破解的难题!

4

3 回答 3

1

看起来这是 Django-CMS 2.1.0beta3 中 URLconf 解析器中的一个错误,该错误已在 dev 中修复。只有在应用程序中包含其他 URLconf 时才会出现该错误。

于 2010-08-12T09:58:44.370 回答
0

更新:

好的,我认为您的错误源于get_absolute_url

@models.permalink
def get_absolute_url(self):
    return ('cmsplugin_publisher_entry_detail', (), {'slug': self.slug})

我怀疑这是因为这最终调用object_detail需要一个位置参数queryset(参见 django/views/generic/list_detail.py)。您可以尝试将其更改为:

    return ('cmsplugin_publisher_entry_detail', [Entry.objects.all(),], {'slug': self.slug})
于 2010-08-07T20:56:39.520 回答
0

我会仔细检查urls/entries.py实际上是在某个地方导入的,否则它将无法获得反向匹配。

于 2010-08-11T23:08:36.747 回答