gpt4 book ai didi

Django CMS apphook 命名空间

转载 作者:行者123 更新时间:2023-12-04 16:52:13 24 4
gpt4 key购买 nike

我正在开发一个日历应用程序作为我的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com