I'm trying to set editable background image of header on my site built using Django CMS.
Tried instructions from Using django-cms, how can I allow the user to specify a background image , but still got "background-image: url('')" in my resulting HTML code.
Here is code that I add to try to add backgroung image:
- context_processors.py in root of project:
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.filerimage.image}
#return {'cover': cover_image_plugin.get_plugin_instance()[0]}
return {}
- End of settings.py:
TEMPLATES[0]['OPTIONS']['context_processors'].append('context_processors.cover_image')
- base.html:
...
{% placeholder "cover_image" %}
<header class="masthead" style="background-image: url('{{ cover.url|urlencode }}')">
...
Could anybody help me to fix it and to make background image work?