I am developing a calendar application as a apphook within my django cms project. I wanted to use namespace, but cant seem to have my urls resolve any more. Here is the 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)
here is the urls.py
within my app:
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'),
)
From my understanding I should be able to reference my urls like so:
{% url 'cab_calendar:calendar' %}
but Django keeps saying:
NoReverseMatch at /en/cab/month/6/2015
u'cab_calendar' is not a registered namespace
what am I doing wrong?
With the way the CMS currently loads apps attached via an apphook you must restart the server once you have attached the app to a page.
The registering of namespaces happens only on server startup, although there is a signal fired when the reload is required so you might be able to hook up something to that signal.
Apphook docs;