Apphooks
We do this with an apphook, created using a CMSApp
sub-class, which tells the CMS how to include that application.
Apphooks live in a file called cms_apps.py
, so create one in your Polls/CMS Integration application, i.e. in polls_cms_integration
.
This is a very basic example of an apphook for a django CMS application:
Instead of defining the URL patterns in another file polls/urls.py
, it also is possible to return them directly, for instance as:
from django.conf.urls import url
class PollsApphook(CMSApp):
# ...
def get_urls(self, page=None, language=None, **kwargs):
url(r'^$', PollListView.as_view()),
url(r'^(?P<slug>[\w-]+)/?$', PollDetailView.as_view()),
In the PollsApphook
class, we have done several key things:
- The
app_name
attribute gives the system a way to refer to the apphook - see for details on why this matters. - The
get_urls()
method is what actually hooks the application in, returning a list of URL configurations that will be made active wherever the apphook is used.
Apply the apphook to a page
Now we need to create a new page, and attach the Polls application to it through this apphook.
Create and save a new page, then publish it.
Note
Your apphook won’t work until the page has been published.
In its Advanced settings, choose “Polls Application” from the Application menu, and save once more.
Refresh the page, and you’ll find that the Polls application is now available directly from the new django CMS page.
You can now remove the mention of the Polls application (url(r'^polls/', include('polls.urls', namespace='polls'))
) from your project’s urls.py
- it’s no longer even required there.
Later, we’ll install a django-CMS-compatible .
Important
Don’t add child pages to a page with an apphook.