Django CMS Apphook 不加载

Django CMS Apphook does not load

我有一个新的 Django CMS 安装程序,安装了以下组件 (requirements.txt):

Django==1.11
Pillow==5.0.0
psycopg2-binary==2.7.4
django-ckeditor==5.4.0
django-cms==3.5.1
djangocms-text-ckeditor>=3.6.0

以及以下文件结构:

.
├── main_app
│   ├── admin.py
│   ├── admin.pyc
│   ├── apps.py
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── migrations
│   ├── models.py
│   ├── models.pyc
│   ├── __pycache__
│   ├── tests.py
│   ├── urls.py
│   ├── urls.pyc
│   ├── views.py
│   └── views.pyc
├── project
│   ├── cms_apps.py
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── local_settings.py
│   ├── local_settings.pyc
│   ├── production.py
│   ├── production.pyc
│   ├── __pycache__
│   ├── settings.py
│   ├── settings.pyc
│   ├── static
│   ├── urls.py
│   ├── urls.pyc
│   ├── wsgi.py
│   └── wsgi.pyc
├── templates
│   ├── 404.html
│   ├── base.html
│   └── ...
├── manage.py
└── requirements.txt

添加Apphook时,无法在高级页面设置中select应用:

project/cms_apps.py:

from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool

@apphook_pool.register
class MainApphook(CMSApp):
    app_name = 'main_app'
    name = 'Main App'

    def get_urls(self, page=None, language=None, **kwargs):
        return ["main_app.urls"]

我在 settings.py 中安装的应用程序:

INSTALLED_APPS = [
    'custom_auth',
    'djangocms_admin_style',

    'django.contrib.sites',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    'djangocms_text_ckeditor',
    'cms',
    'menus',
    'treebeard',
    'sekizai',
    'ckeditor',

    'main_app',
]

我已经按照http://docs.django-cms.org/en/latest/introduction/apphooks.html

的教程重启了服务器

注意没有project/cms_apps.pyc

据我所知,我完全遵循了 Apphook 教程,所以我还缺少什么?

好的,所以您的应用程序中需要一个 cms_apps.py 模块来连接到 CMS。

例如,我有一个名为 djangocms_forms 的应用,它 cms_apps.py 看起来像这样;

class DjangoCMSFormsApphook(CMSApp):
    """ Add docs """
    name = _('Forms')
    urls = ['djangocms_forms.urls']


apphook_pool.register(DjangoCMSFormsApphook)

它有以下网址;

urlpatterns = [
    url(r'^forms/submit/$', FormSubmission.as_view(),
        name='djangocms_forms_submissions'),
    url(r'^forms/redirect/$', media_redireect,
        name='djangocms_forms_redirect')
]

然后访问这些 URL 时没有任何命名空间,例如 reverse('djangocms_forms_submissions')

但是,您可以通过将 app_name 属性添加到 CMSApp 来添加命名空间。例如,我有另一个应用程序 gallery,其配置如下;

class GalleryApp(CMSApp):
    """ Gallery CMS app """
    app_name = 'gallery'
    name = _("Gallery App")
    urls = ["gallery.urls"]

此应用程序的 URL 定义为 {% url "gallery:filterable_gallery_data" %} 或在 python 中定义为 reverse('gallery:filterable_gallery_data')