tags:

views:

139

answers:

2

I have a django application.I have added image (url) in css,it isn't displaying the image.

But when I used it as a html file,it is displaying the image.Should I set any url in settings.py for this? Source [shown here][1]. [1]: http://dpaste.com/164620/

A: 

is /home/logic/quote/template/hummingbirds.gif your image web path? it look like a local path. does it show when you type http://your.host/home/logic/quote/template/hummingbirds.gif

if you set a background-color, does the color appear?

suggestion: on firefox with firebug:

  • enable css warning
  • lokks at the parsed css file (css tab) to see if your rule is well writen
  • inspect the element your background should be on and verify it has the css rule applied and not overwriten
mathroc
Color is appearing but image isn't displayed.
DAFFODIL
+1  A: 

That is definitely a local path. You need either a path relative to the doc root (by default, Django doesn't serve media files, it's discouraged to let it do that outside testing environments) or an absolute URL if the file is on a different (sub-)domain (e.g. a local Apache vhost that serves the media files).

If you're using relative paths, beware that the path will be relative to the page the path is mentioned on (i.e. if you put it in a CSS file, it will be relative to the CSS file; if you put it in a template, it will be relative to whatever page is shown with that template).

If you're using absolute paths, beware that the path will be relative to the doc root of that (sub-)domain.

EDIT: NO, really. It's the path. A path in CSS or HTML will be parsed by your browser. So even if you run the thing on localhost, an absolute path (starting with /) will be parsed as relative to the document root (i.e. handed over to Django's URL resolution).

If you have the site running on http://localhost:8000, /home/logic/quote/template/hummingbirds.gif will be treated as http://localhost:8000/home/logic/quote/template/hummingbirds.gif, i.e. your browser will make a HTTP GET request to the server running at localhost:8000 for the path /home/logic/quote/template/hummingbirds.gif. If the server is Django, it will try to find a rule matching /home/logic/quote/template/hummingbirds.gif in your urls.py. You can't refer to a file in your filesystem by just passing the local path.

If you want to serve static files (e.g. images) with Django (i.e. on the same domain and port Django runs on), you need to configure it to serve these files first like so: http://docs.djangoproject.com/en/dev/howto/static-files/

If you want to refer to a file on your filesystem (BAD practice and needs to be replaced if the thing EVER goes online), you need to use the file:// protocol explicitly. Absolute URLs (i.e. without protocol prefix and domain name) will always be treated as relative to the current protocol and domain.

Alan
It is still in the development,i have n't hosted my application,I mentioned every thing very clearly,it is still in the development.I have to use local path only,the path is absolutely correct,but i m making mistake some where else,i have even given my source code.
DAFFODIL
@DAFFODIL see my edit for a full explanation of what might be going on.
Alan
@alan: I followed your guide lines but,it is still the same.See the changes that,i made http://dpaste.com/hold/165122/
DAFFODIL