Python Django CMS 2.1.0应用程序扩展名NoReverseMatch TemplateSyntaxer错误

Python Django CMS 2.1.0应用程序扩展名NoReverseMatch TemplateSyntaxer错误,python,django,django-cms,Python,Django,Django Cms,我正在为Django CMS编写一个自定义应用程序,但在尝试查看管理员中发布的条目时,出现以下错误: TemplateSyntaxError位于/admin/cmsplugin_publisher/entry/ 呈现时捕获到NoReverseMatch:未找到参数为“()”且关键字参数为“{slug':u'test-derman'}”的“cmsplugin\u publisher\u entry\u detail”的反向 如果我在主应用程序URL.py中给应用程序一个URL,我可以让应用程序工作

我正在为Django CMS编写一个自定义应用程序,但在尝试查看管理员中发布的条目时,出现以下错误:

TemplateSyntaxError位于/admin/cmsplugin_publisher/entry/

呈现时捕获到NoReverseMatch:未找到参数为“()”且关键字参数为“{slug':u'test-derman'}”的“cmsplugin\u publisher\u entry\u detail”的反向

如果我在主应用程序URL.py中给应用程序一个URL,我可以让应用程序工作,但这会将应用程序修复为所需的URL,我只想扩展Django CMS,这样应用程序将来自添加到的任何页面

models.py绝对URL模式

    @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'),
)
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)
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
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)
视图/装饰器.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'),
)
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)
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
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)
应用程序与Django CMS的集成说明如下:

看起来问题可能在于我在应用程序中使用的是通用视图和自定义的mis,因此没有正确返回RequestContext

CMS应用程序扩展名py文件:

cms_app.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'),
)
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)
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
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)
任何一个指针都值得赞赏,这是一个很难破解的难题

更新:

好的,我认为您的错误源于
get\u absolute\u url

@models.permalink
def get_absolute_url(self):
    return ('cmsplugin_publisher_entry_detail', (), {'slug': self.slug})
我怀疑这是因为这最终调用了
object\u detail
,它需要一个位置参数
queryset
(请参见django/views/generic/list\u detail.py)。您可以尝试将其更改为以下内容:

    return ('cmsplugin_publisher_entry_detail', [Entry.objects.all(),], {'slug': self.slug})

我会仔细检查
url/entries.py
是否确实被导入到某个地方,否则它将无法获得反向匹配。

看起来像是Django CMS 2.1.0beta3中的URLconf解析器中的一个bug,它是。只有在应用程序中包含其他URLConf时才会出现此错误。

这没有什么区别:slug\u字段默认使用“slug”-这是模型的一部分。没错,没有注意到slug\u字段的默认值。。我已经更新了我的答案。希望这能有所帮助。我认为关于Poissional元素您是对的,但是您的编辑提高了:呈现时捕获的ValueError:在调用reverse()时不要混合使用*args和**kwargs!所以这个问题一定是在其他地方出现的,也许只是为object_detail创建一个包装函数,它接受两个位置参数(Entry.objects.all和self.slug),然后调用object_detail。在get_absolute_url中指定包装函数。如果这样做行得通,至少你会知道你走对了方向。似乎不是这样,它在文件夹/url/importing entries.py中,通过init.py在文件夹中。当主网站URL.py中为应用程序提供了一个绝对URL时工作正常-当然我只想扩展django cms URL,所以这不是一个我可以使用的解决方案。这完全解决了它。谢谢你,杰森!