Search code examples
djangofeincms

How can I retrieve data from a page?


I am using FeinCMS. I want to do some processing on a page object before it goes to the template for rendering.

In my view I have the code :

this_page = Page.objects.best_match_for_path(request.path)

which correctly gets the page for the path I am on.

I really want to get some data out of this page.

Is there a function I can call to get the data ? such as :

this_page = Page.objects.best_match_for_path(request.path)
data = this_page.get_content_for_region('main')

I can't find anything in the readthedocs pages to answer this. I am not interested in templates or rendering the region.


Solution

  • Just use this_page.content - it's a ContentProxy that makes all content types of your regions available. In other words, if you have a template definition like so:

    Page.register_templates({
        'title': 'Standard template',
        'path': 'base.html',
        'regions': (
            ('main', 'Main content area'),
            ('sidebar', 'Sidebar'),
        ),
    })
    

    You can loop over this_page.content.mainand this_page.content.sidebar:

    for content in this_page.content.main:
        print(content.render())