DJANGO-CMS Code Research (eight) app hooks

Source: Internet
Author: User

App Hooks, what's the thing?

is a means of integrating existing apps into a CMS.

There are two ways to achieve this:

1) define the cms_app.py as follows:

From cms.app_base import cmsappfrom cms.apphook_pool import apphook_poolfrom django.utils.translation import Ugettext_ Lazy as _class Myapphook (cmsapp):    name = _ ("My apphook")    urls = ["Myapp.urls"]apphook_pool.register (Myapphook)

Official documents See here: Http://docs.django-cms.org/en/latest/extending_cms/app_integration.html#app-hooks

Load logic, loaded via Discover_apps's Load (' Cms_app ') (if cms_apphooks is not defined in settings.py): In all Installed_app, find the Cms_app module, and automatically Import_module

2) define Cms_apphooks in setting.py

apphooks= (' Yourmodule.you_object1 ', ' Yourmodule.you_object2 ',...)

This is from the source code analysis, the following:

C:\Python27\Lib\site-packages\django_cms-3.0.3-py2.7.egg\cms\apphook_pool.py (45~57)

    def discover_apps (self):        self.apphooks = get_cms_setting (' apphooks ')        if self.apphooks: for            CLS in Iterload_objects (self.apphooks):                try:                    self.register (CLS, discovering_apps=true)                except appalreadyregistered:                    Pass        else:            load (' Cms_app ')        self.discovered = True

Iterload_objects, is a generator, as follows:

def iterload_objects (import_paths): "" "    Load a list of objects.    " " For Import_path in import_paths:        yield load_object (import_path)

Load_object

def load_object (Import_path):    if '. ' Not in Import_path:        raise TypeError (            "' import_path ' argument to ' Django_load.core.load_object ' must "            " contain at least one dot. "        )    Module_name, object_name = Import_path.rsplit ('. ', 1)    module = import_module (module_name)    return GetAttr ( module, object_name)

  



 

DJANGO-CMS Code Research (eight) app hooks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.