How to provide background image via url() in django

3,524 views
Skip to first unread message

sunday honesty

unread,
Jul 16, 2020, 7:08:11 PM7/16/20
to Django users
Hi django users, pls help me with this:

In case we supply background image via the url() function as
background-image: url("some_path/image.png")

How do we do this in django static files?
I tried

url("{% static 'some_path/image.png' %}")

but it didn't work, how do I do this pls?

Desh Deepak

unread,
Jul 16, 2020, 10:34:35 PM7/16/20
to django...@googlegroups.com
Try it

url(" static 'some_path/image.png' ")

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c711150b-910c-4cbb-9823-48e0657fe352o%40googlegroups.com.

Exactly musty

unread,
Jul 17, 2020, 12:54:40 AM7/17/20
to Django users
i encounter alot shit when adding static to a url background images,django templates can be shitty sometimes,because sometimes it wont pick up due to some spacing ,its very annoying,here is what i do either i write the same code by myself again beneath it but mostly it always worked by copying another url background image then i edit it,let me explain, in your templates you must have another url background images you have added static to and it worked just copy it beneath your main problem then edit it after editing delete the problem and restart your dev server

Sujata Aghor

unread,
Jul 17, 2020, 1:08:19 AM7/17/20
to django...@googlegroups.com
I set background image like below in the style tag of the html page. It works !

<style>
   body{
    background: url({% static 'users/img/bg/name_of _image.png'%}) no-repeat center center fixed;
    -webkit-background-size:cover;
    -moz--background-size:cover;
    -o--background-size:cover;
    background-size: cover;
   }
</style>



--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c711150b-910c-4cbb-9823-48e0657fe352o%40googlegroups.com.


--

Thanks & Regards!
Sujata S. Aghor

sunday honesty

unread,
Jul 17, 2020, 2:38:38 AM7/17/20
to django...@googlegroups.com
Thanks all...

@Sujara own worked for me

Reply all
Reply to author
Forward
0 new messages