我有一个新的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时,无法在高级页面设置中选择“应用程序”:
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教程,所以我缺少了什么?
答案 0 :(得分:1)
好的,因此您需要在应用中使用一个cms_apps.py
模块,并将其连接到CMS。
例如,我有一个名为djangocms_forms
的应用,它的cms_apps.py
看起来像这样;
class DjangoCMSFormsApphook(CMSApp):
""" Add docs """
name = _('Forms')
urls = ['djangocms_forms.urls']
apphook_pool.register(DjangoCMSFormsApphook)
它具有以下URL;
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 "gallery:filterable_gallery_data" %}
或在python中定义为reverse('gallery:filterable_gallery_data')