Django CMS 2.1.0 应用程序扩展 NoReverseMatch TemplateSyntaxError

发布于 2024-09-13 10:48:13 字数 3282 浏览 1 评论 0原文

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

模板语法错误位于 /admin/cmsplugin_publisher/entry/

渲染时捕获 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'),
)

views/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)

views/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 应用程序扩展 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)

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

I'm writing a custom app for Django CMS, but get the following error when trying to view a published entry in the admin:

TemplateSyntaxError at /admin/cmsplugin_publisher/entry/

Caught NoReverseMatch while rendering: Reverse for 'cmsplugin_publisher_entry_detail' with arguments '()' and keyword arguments '{'slug': u'test-german'}' not found.

I can get the app working if I give the app a URL in my main application urls.py, but that fixes the app to a required URL, I just want extend Django CMS so the app will come from whichever page it's added to.

models.py Absolute URL Pattern

    @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'^

views/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)

views/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

The app integration with Django CMS is explained here: http://github.com/divio/django-cms/blob/master/cms/docs/app_integration.txt

It looks like the issue might be that I'm not correctly returning the RequestContext as I'm using a mis of generic views and custom in the application.

The CMS App extension py file:

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)

Any pointers appreciated, it's proving to be a tough nut to crack!

, 'entry_index', entry_conf_list, name='cmsplugin_publisher_entry_archive_index'), url(r'^(?P<page>[0-9]+)/

views/entries.py


views/decorators.py


The app integration with Django CMS is explained here: http://github.com/divio/django-cms/blob/master/cms/docs/app_integration.txt

It looks like the issue might be that I'm not correctly returning the RequestContext as I'm using a mis of generic views and custom in the application.

The CMS App extension py file:

cms_app.py


Any pointers appreciated, it's proving to be a tough nut to crack!

, 'entry_index', entry_conf_list, name='cmsplugin_publisher_entry_archive_index_paginated'), ) urlpatterns += patterns('django.views.generic.list_detail', url(r'^(?P<slug>[-\w]+)/

views/entries.py


views/decorators.py


The app integration with Django CMS is explained here: http://github.com/divio/django-cms/blob/master/cms/docs/app_integration.txt

It looks like the issue might be that I'm not correctly returning the RequestContext as I'm using a mis of generic views and custom in the application.

The CMS App extension py file:

cms_app.py


Any pointers appreciated, it's proving to be a tough nut to crack!

, 'object_detail', entry_conf_detail, name='cmsplugin_publisher_entry_detail'), )

views/entries.py

views/decorators.py

The app integration with Django CMS is explained here: http://github.com/divio/django-cms/blob/master/cms/docs/app_integration.txt

It looks like the issue might be that I'm not correctly returning the RequestContext as I'm using a mis of generic views and custom in the application.

The CMS App extension py file:

cms_app.py

Any pointers appreciated, it's proving to be a tough nut to crack!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

-柠檬树下少年和吉他 2024-09-20 10:48:16

更新:

好的,我认为您的错误源自 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})

UPDATE:

OK, I think your error originates from get_absolute_url:

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

I suspect it's because this ultimately calls object_detail which expects a positional parameter queryset (see django/views/generic/list_detail.py). You could try changing this to something like:

    return ('cmsplugin_publisher_entry_detail', [Entry.objects.all(),], {'slug': self.slug})
挥剑断情 2024-09-20 10:48:16

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

I would double-check that urls/entries.py is actually being imported somewhere otherwise it won't be able to get the reverse match.

故事未完 2024-09-20 10:48:15

看起来这是 Django-CMS 2.1.0beta3 中的 URLconf 解析器中的一个错误,已修复在开发中。该错误仅在应用程序内包含其他 URLconf 时才会发生。

Looks like it's a bug in the URLconf parser in Django-CMS 2.1.0beta3, which is fixed in dev. The bug only occurs when including other URLconfs from within an app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文