Django CMS apphook名称空间

时间:2015-06-18 16:36:21

标签: django namespaces django-cms

我正在开发一个日历应用程序作为我的django cms项目中的apphook。我想使用命名空间,但似乎不能再让我的网址解析了。这是CheckBox dummy

cms_app.py

这是我的应用中的from cms.app_base import CMSApp from cms.apphook_pool import apphook_pool from django.utils.translation import ugettext_lazy as _ class SchedulerApphook(CMSApp): name = _("Scheduler") urls = ["scheduler_app.urls"] app_name = "cab_calendar" apphook_pool.register(SchedulerApphook)

urls.py

根据我的理解,我应该能够像我这样引用我的网址:

from django.conf.urls import patterns, include, url
from . import views
from scheduler_app.views import EventList, EventDetail
from datetime import datetime
from django.views.generic.base import RedirectView


urlpatterns = patterns('',

    # Monthly views
    url(r'^month/(1[0-2]{1}|[1-9]{1})/([0-2][0-9]{3})', views.calendar , name='calendar'),  #cab/month/1-12/1900-2999
    url(r'^month', RedirectView.as_view(url ='/cab/month/%s/%s' % (datetime.now().month, datetime.now().year)), name='today'), ## monthly view of today

    # Weekly view
    url(r'^week/(?P<day>((3[0-1]{1})|([1-2]{1}[0-9]{1})|([1-9]{1})))/(?P<month>(1[0-2]{1}|[1-9]{1}))/(?P<year>([1-2][0-9]{3}))', views.week_calendar, name='week_calendar'),
    url(r'^week', RedirectView.as_view(url ='/cab/week/%s/%s/%s' % (datetime.now().day, datetime.now().month, datetime.now().year)), name='week_calendar'),

    # Daily views
    url(r'^day/(?P<day>((3[0-1]{1})|([1-2]{1}[0-9]{1})|([1-9]{1})))/(?P<month>(1[0-2]{1}|[1-9]{1}))/(?P<year>([1-2][0-9]{3}))' , views.day_calendar , name='day_calendar'), #cab/day/1-31/1-12/1900-2999
    url(r'^day', RedirectView.as_view(url = '/cab/day/%s/%s/%s' % (datetime.now().day, datetime.now().month, datetime.now().year)), name='day_calendar'),   # daily view of today

    url(r'^events', EventList.as_view(), name='events'),
    url(r'^event/(?P<pk>\d+)', EventDetail.as_view(), name='event_detail'),

    # No selected view -> default = today monthly 
    url(r'^.*', RedirectView.as_view(url ='/cab/month/%s/%s' % (datetime.now().month, datetime.now().year)), name='today'),
)

但是Django一直在说:

   / en / cab / month / 6/2015的NoReverseMatch

     

U&#39; cab_calendar&#39;不是注册名称空间

我做错了什么?

1 个答案:

答案 0 :(得分:0)

通过CMS当前加载通过apphook附加的应用程序的方式,您必须在将应用程序附加到页面后重新启动服务器。

命名空间的注册仅在服务器启动时发生,尽管在需要重新加载时会触发信号,因此您可以将某些信息连接到该信号。

Apphook docs;

  

如上所述,无论何时添加或删除apphook,更改包含apphook或slug的页面的slug如果页面具有带apphook的后代,则必须重新启动服务器以重新加载URL缓存。为了让您自动执行此过程,django CMS提供了一个信号double answer = 0.0; if (x==S516){ answer = (S516 * x * 1.1 / 60); } else if (x==A304){ answer = (A304 * x * 1.1 / 60); } ,您可以监听该信号以检测服务器何时需要重新启动。运行manage.py runserver时,不需要重新启动。