我正在为Django CMS编写自定义应用程序,但在尝试查看管理员中的已发布条目时出现以下错误:
/ admin / cmsplugin_publisher / entry /
中的TemplateSyntaxError渲染时捕获NoReverseMatch:反向'cmsplugin_publisher_entry_detail',参数'()'和关键字参数'{'slug':u'test-german'}'找不到。
如果我在主应用程序urls.py中为应用程序提供了一个URL,我可以让应用程序正常工作,但这会将应用程序修复为所需的URL,我只想扩展Django CMS,以便应用程序来自添加的任何页面到。
models.py绝对网址格式
@models.permalink
def get_absolute_url(self):
return ('cmsplugin_publisher_entry_detail', (), {
'slug': self.slug})
的URL / 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'),
)
视图/ entries.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)
视图/ decorators.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 App扩展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)
任何指示赞赏,它被证明是一个难以破解的坚果!
答案 0 :(得分:1)
看起来它是Django-CMS 2.1.0beta3中URLconf解析器中的一个错误,它是fixed in dev。只有在应用程序中包含其他URLconf时才会出现该错误。
答案 1 :(得分: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})
答案 2 :(得分:0)
我会仔细检查urls/entries.py
实际上是否正在某处导入,否则将无法获得反向匹配。