Follow these steps to convert a usual movies Django app to a Django CMS app:
- First of all, remove or comment out the inclusion of the URL configuration of the app, as it will be included by apphook in Django CMS, as follows:
# myproject/urls.py
# ... urlpatterns = [
# ... # remove or comment out the inclusion of app's urls # path("movies/", include("movies.urls")),
# ...
]
- Create a cms_apps.py file in the movies directory and create MoviesApphook there, as follows:
# movies/cms_apps.py from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool
from django.utils.translation import ugettext_lazy as _
@apphook_pool.register
class MoviesApphook(CMSApp):
app_name = "movies"
name = _("Movies")
def get_urls(self, page=None, language=None, **kwargs):
return ["movies.urls"]
- By default, the CMS will automatically discover your apphooks by searching each app in INSTALLED_APPS for the preceding magic file. If you only want to wire in specific apps instead, you can set the newly created apphook in the CMS_APPHOOKS settings, as shown in the following code:
# settings.py or config/base.py CMS_APPHOOKS = (
# ...
"movies.cms_apps.MoviesApphook",
)
- Finally, in all of the movie templates, change the first line to extend from the template of the current CMS page, instead of extending base.html, as follows:
{# templates/movies/movies_list.html #} {% comment %}
Change {% extends "base.html" %} to: {% endcomment %}
{% extends CMS_TEMPLATE %}