问题描述:

I have a simple website that I need to set a background image as a style as below

<header class="intro-header" style="background-image: url('static/img/home-bg.jpg')">

which is from a sample example site.

I seem to be stuck on getting the above to work in a Django template. I have tried

<header class="intro-header" style="background-image: url('{% static "img/home-bg.jpg" %}')">

but its not working.

I am using manage.py runserver with static_url and STATICFILES_DIRS set as follows:

STATIC_URL = '/static/'

MAIN_PROJECT = os.path.dirname(__file__)

STATICFILES_DIRS = (

os.path.join(MAIN_PROJECT, 'static/'),

)

I have my template in ContainerFolder\homeapp\templates\homeapp\index.html.

I have put the image files in a toplevel static folder ie in ContainerFolder\Static\Img because I want to avail them to all apps.

相关阅读:
Top