Reputation: 1731
I have a new setup of Django CMS with the following components installed (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
And the following file structure:
.
├── 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
When I add an Apphook, I cannot select the Application in the advanced page settings:
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"]
My installed apps in 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',
]
I have restarted the server according to the tutorial at http://docs.django-cms.org/en/latest/introduction/apphooks.html
Note that there is no project/cms_apps.pyc
As far as I can tell, I followed the Apphook tutorial exactly, so what am I missing?
Upvotes: 1
Views: 640
Reputation: 12849
Ok, so you need a cms_apps.py
module in your app that gets hooked into the CMS.
For example I've got an app called djangocms_forms
and it's cms_apps.py
looks like this;
class DjangoCMSFormsApphook(CMSApp):
""" Add docs """
name = _('Forms')
urls = ['djangocms_forms.urls']
apphook_pool.register(DjangoCMSFormsApphook)
It has the following URLs;
urlpatterns = [
url(r'^forms/submit/$', FormSubmission.as_view(),
name='djangocms_forms_submissions'),
url(r'^forms/redirect/$', media_redireect,
name='djangocms_forms_redirect')
]
Those URLs are then accessed without any namespacing like reverse('djangocms_forms_submissions')
However you can add the namespacing by adding the app_name
attribute to the CMSApp
. For example I've got another app, gallery
which is configured like;
class GalleryApp(CMSApp):
""" Gallery CMS app """
app_name = 'gallery'
name = _("Gallery App")
urls = ["gallery.urls"]
URLs for this app then are defined like, {% url "gallery:filterable_gallery_data" %}
or in python as reverse('gallery:filterable_gallery_data')
Upvotes: 1