How to do it...

Follow these steps to convert a usual movies Django app to a Django CMS app:

  1. 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")),
# ...
]

  1. 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"]
  1. 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",
)
  1. 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 %}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.178.165