0

okay so I didn't make any changes to my settings.py, the image I want to use in my css is here.

C:\djcode\testapp1\testing1\testingapp1\static\testingapp1\images

my style.css file is in here.

C:\djcode\testapp1\testing1\testingapp1\static\testingapp1

my manage.py file is in here.

C:\djcode\testapp1\testing1

and my settings.py file is in here.

C:\djcode\testapp1\testing1\testing1

My templates (including index.html) are here.

C:\djcode\testapp1\testing1\testingapp1\templates

In my index.html file, I linked the css by typing this on the top of my index.html file.

{% load staticfiles %}
<link rel="stylesheet" type="text/css" href="{% static 'testingapp1/style.css' %}" />

I tried using the image in my css file by doing this.

background: url(images/picture.png);

I also tried.

background: url({% static 'testingapp1/images/picture.png' %})

but that didn't work either. Any idea what is wrong?

3
  • 1
    What's your STATIC_ROOT path? Commented Jul 28, 2013 at 0:48
  • my static root is just STATIC_ROOT = '', STATIC_URL = '/static/' and no STATICFILES_DIRS... I was afraid that if I added a static_root or static_url that it might mess up my linking to the css in my index.html Commented Jul 28, 2013 at 1:09
  • Perhaps this can help you: stackoverflow.com/questions/14799835/… - Furthermore I would definately not recommend using Django template tags within your static resources. The reasoning behind that is because you have to serve these via the template pipeline (ie. compile them and serve) or use inline scripts and css. And THAT is really, really bad. Commented Jul 29, 2013 at 11:59

1 Answer 1

1

You need to define STATIC_ROOT, and also set your STATICFILE_DIRS for local development, otherwise Django won't know where to serve your local static files during development.

STATIC_ROOT is where your static media and any 3rd party static media get collected to for deployment. STATICFILES_DIRS is the directory or directories django.contrib.static will serve files from if DEBUG is True.

Hope that gets you going.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.