0

I am new to Django and am trying to learn how to serve static files in local deployment. I have read this and many other possible related problems from stackoverflow but i cant seem to be able to find solve my problem.

This is my settings , I cant figure out what is the reason Django isnt serving my static files

STATIC_ROOT = ''
STATIC_URL = '/html/'
STATICFILES_DIRS=('C:/Users/RayLim/Desktop/project/home/username/djcode/mysite/mysite/templates/html',)

In my templates I refer to them as

<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />

The structure of my html file which is located at C:/Users/RayLim/Desktop/project/home/username/djcode/mysite/mysite/templates

html
 /css
  /images
  /style.css
 /js
  /jquery.jcarousel.pack
  /jquery-1.4.1.min
  /jquery-func

This is the server response

"GET /home/css/images/big1.jpg HTTP 1.1" 404 3782
user2284926
  • 661
  • 2
  • 10
  • 20

2 Answers2

0

You should avoid hard linking to your static directories. It can cause confusion and potential problems as your project gets bigger

Please refer to this, it has everything you need.

Django staticfiles app help

Community
  • 1
  • 1
stupidbodo
  • 466
  • 1
  • 5
  • 14
  • @stupidboo correct , i tried reading the link but i didnt quite get how to do it , i learn better by following examples. Do you have any examples to follow??? – user2284926 May 02 '13 at 03:41
0

First, static files and templates are usually in separate directories but I don't think there would be any problem (that I'm aware of...)

Next, you want to make sure that you use a template tag to represent the static file location instead of using css/.. which expects there to be a css directory relative to whatever url you are currently viewing.

There are a couple template tags you can use, I use {{ STATIC_URL }}

So replace

<link rel="stylesheet" href="css/style.css" type="text/css" media="all" />

with

<link rel="stylesheet" href="{{ STATIC_URL }}css/style.css" type="text/css" media="all" />

And you should be all set...

Ngenator
  • 10,909
  • 4
  • 41
  • 46