Django CMS apphook 命名空间

标签 django namespaces django-cms

我正在开发一个日历应用程序作为我的 django cms 项目中的 apphook。我想使用命名空间,但似乎无法再解析我的 url。这是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'),
)

根据我的理解,我应该能够像这样引用我的网址:
{% url 'cab_calendar:calendar' %}

但 Django 一直在说:

NoReverseMatch at /en/cab/month/6/2015

u'cab_calendar' is not a registered namespace



我究竟做错了什么?

最佳答案

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

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

Apphook docs ;

As mentioned above, whenever you add or remove an apphook, change the slug of a page containing an apphook or the slug if a page which has a descendant with an apphook, you have to restart your server to re-load the URL caches. To allow you to automate this process, the django CMS provides a signal cms.signals.urls_need_reloading which you can listen on to detect when your server needs restarting. When you run manage.py runserver a restart should not be needed.

关于Django CMS apphook 命名空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30921039/

相关文章:

django - 具有多个应用程序和数据库的单元测试项目 - TEST [DEPENDENCIES] 中的循环依赖

xml - XSLT 命名空间和 XML 文档没有一个 - 它是如何工作的

django - 在 Heroku 上部署 Django cms

c# - 在不影响客户端的情况下更改 WCF 项目的命名空间

css - Django CMS 菜单,如何只为 parent 设置一个类(class)?

django - 防止Collectstatic尝试访问数据库

Django 迁移 - 禁用系统检查

python - 如何跟随 Django 中的按钮单击?

python - 尝试使用 django 美味馅饼发布时出现 404 错误

c++ - 在命名空间中定义类的方法