How to include a mezzanine page with a given slug in the base template?

I am trying to include a page edited with mezzanine admin on all pages of my site. I read the Mezzanine document and the source and cannot figure out how to do this.

From the docs, I thought that I could pass my page as an additional context, for example:

mezzanine.pages.views.page(request, slug, template=u'pages/page.html', extra_context={'mypage':<get_page_by_its_slug>}) 

But the document says that the additional context is the mezzanine.pages.middleware.PageMiddleware object, which sets the slug from the request.

Do I need to write a context processor for this? How to load a specific page with your bullet?

+4
source share
1 answer

Just in case, this helps someone, I created a context processor for this:

 # context_processors.py from mezzanine.pages.models import Page def featured(request): # editable page, get by ID or slug or title... featured_page = Page.objects.get(id=49) return {'featured_page': featured_page} 

added a context handler to my .py settings:

 TEMPLATE_CONTEXT_PROCESSORS = ( "django.contrib.auth.context_processors.auth", ## ...etc..., "myapp.context_processors.featured", ) 

and included the displayed content in the base.html template:

 {% block right_panel %} <div> {% editable featured_page.richtextpage.content %} {{ featured_page.richtextpage.content|richtext_filter|safe }} {% endeditable %} </div> {% endblock %} 

If you know an easier way to do this, I would love to hear your decision!

+7
source

Source: https://habr.com/ru/post/1481295/


All Articles