Using django-cms, how can I allow the user to specify a background image

前端 未结 3 1525
无人及你
无人及你 2021-01-13 05:34

I am creating a django-cms site for a client. I would like to do something like:



        
3条回答
  •  时光说笑
    2021-01-13 05:57

    Great answer Flimm, thanks!

    I get an error, however, in the context processor saying that a CMSPlugin object does not have a filerimage attribute. Here's the context processor that works for me:

    # in context_processors.py
    from cms.models.pluginmodel import CMSPlugin
    
    def cover_image(request):
        page = request.current_page
        if page:
            cover_image_plugin = CMSPlugin.objects.filter(
                placeholder__page=page,
                placeholder__slot='cover_image',
                plugin_type='FilerImagePlugin',
            ).first()
            if cover_image_plugin:
                return {'cover': cover_image_plugin.get_plugin_instance()[0]}
        return {}
    

    Note the change in the but last line. get_plugin_instance retrieves the rightly subclassed instance object as the first entry of a tuple. (I use Django CMS 3.4)

    As a last remark, the cover_image placeholder needs to be in a place that is not rendered.

提交回复
热议问题