2010-08-07 65 views
0

我正在寫的Django CMS的自定義應用程序,但在嘗試查看管理員發佈的條目時出現以下錯誤:Django的CMS 2.1.0應用擴展NoReverseMatch TemplateSyntaxError

TemplateSyntaxError在/管理/ cmsplugin_publisher/entry/

渲染時捕獲NoReverseMatch:未找到參數'()'和關鍵字參數'{'slug':u'test-german'}'的'cmsplugin_publisher_entry_detail'。

我可以獲取應用程序的工作,如果我給應用程序在我的主要應用urls.py一個網址,但修復了應用所需的URL,我只是想延長Django的CMS,因此該應用會從哪個它被添加到的頁面。

models.py絕對URL模式

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

網址/ 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應用擴展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) 

讚賞任何指針,它證明是一個難啃的骨頭!

回答

1

看起來這是Django-CMS 2.1.0beta3中的URLconf解析器中的一個錯誤,它是fixed in dev。該錯誤僅在應用程序中包含其他URLconf時纔會發生。

+0

這是完美的固定。謝謝傑森! – Chris 2010-08-12 14:36:22

0

UPDATE:

OK,我想從get_absolute_url您的錯誤來源:

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

我懷疑這是因爲這最終調用object_detail這需要一個位置參數queryset(見的Django /視圖/通用/ list_detail的.py)。你可以試試這個改變的東西,如:

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

這沒什麼區別:slug_field默認使用'slug' - 這是模型的一部分。 – Chris 2010-08-11 07:59:23

+0

你是對的,沒有注意到slug_field的默認值。我已經更新了我的答案。希望這會得到某個地方。 – ars 2010-08-11 17:38:14

+0

我認爲你是正確的,但你的編輯提出了: 抓住ValueError呈現時:不要在調用reverse()時混合* args和** kwargs! 所以它必須在其他地方發生此問題 – Chris 2010-08-12 07:53:22

0

我會仔細檢查urls/entries.py實際上是被導入的地方,否則將無法獲得反向匹配。

+0

似乎並不是這樣,它通過文件夾中的__init__.py文件夾/ URL /導入entries.py。當應用程序的絕對URL被賦予int主網站urls.py時工作正常 - 儘管我當然只想擴展django-cms的URL,所以這不是我可以使用的解決方案。 – Chris 2010-08-12 08:01:53