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?

user216485
  • 719
  • 2
  • 10
  • 23
  • 1
    What's your `STATIC_ROOT` path? – dan-klasson Jul 28 '13 at 00: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 – user216485 Jul 28 '13 at 01:09
  • Perhaps this can help you: http://stackoverflow.com/questions/14799835/django-static-files-results-in-404/14800489#14800489 - 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. – Henrik Andersson Jul 29 '13 at 11:59

1 Answers1

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.

Brandon Taylor
  • 33,823
  • 15
  • 104
  • 144