0

I'm new to django. so I need your help. I am having a problem, my css and jpgs are missing. I read this tutorial Managing static files. But found no luck. Can any one help me?? thanks

setting.py

STATIC_ROOT = 'C:/Users/khalsa/projects/template2/static'
STATIC_URL = '/static/'

INSTALLED_APPS = (
    'django.contrib.staticfiles',
)

URL setting

if settings.DEBUG:
urlpatterns += patterns('',
    url(r'^static/(?P<path>.*)$', 'django.views.static.serve', {
        'document_root': settings.STATIC_ROOT,
    }),
 )

Image Path

<img src="{{ STATIC_URL }}images/11.jpg" alt="image" />
no_freedom
  • 1,963
  • 10
  • 30
  • 48
  • Please define "are missing." Are you unable to access them by URL (which URL?) or have they vanished from your hard drive? – George Cummins Jun 24 '11 at 17:39
  • @George Cummins I'm trying to display images. which is located in `static/images/` folder. Generic view `(r'^test/$', list_detail.object_list, product_info),` – no_freedom Jun 24 '11 at 17:48
  • What version of Django are you using, and are you using `manage.py runserver` or a real web server? – George Cummins Jun 24 '11 at 17:51
  • @George Cummins Django version is 1.3.0 Final. and I'm using it localhost. yes ` manage.py runserver` – no_freedom Jun 24 '11 at 17:53

1 Answers1

0

There are a few things to check.

  1. Did you run ./manage.py collectstatic? Did the process successfully copy your files to 'C:/Users/khalsa/projects/template2/static'?

  2. Localhost issues: Is Django is using 'http://127.0.0.1/static/' and you are using 'http://localhost/static/' in your browser, or vice-versa?

  3. Finally, you will need to determine if runserver serves the static files. The documentation says "Deploy those files by configuring your webserver of choice to serve the files in STATIC_ROOT at STATIC_URL." I am not sure manage.py runserver does this by default.

George Cummins
  • 28,485
  • 8
  • 71
  • 90
  • thanks for reply. 1 All files successfully copied. using `manage.py collectstatic`. 2. Django is using `http://127.0.0.1` but `http://127.0.0.1/static `is not working. – no_freedom Jun 24 '11 at 18:21
  • According to http://stackoverflow.com/questions/4565935/django-staticfiles-app-help, Django docs recommend that you do not place your files in STATIC_ROOT. Instead, they should be placed elsewhere and then be collected by `collectstatic`. Did you save them elsewhere? As a workaround, you can add (or edit) this setting: `STATICFILES_DIRS = (STATIC_ROOT,)` – George Cummins Jun 24 '11 at 18:27
  • what does this mean? `Django docs recommend that you do not place your files in STATIC_ROOT` – no_freedom Jun 24 '11 at 18:38
  • @user559744: the idea behind `collectstatic` is that your static files are stored in various places, and the command will find all of those places and copy the files into STATIC_ROOT. If your files are already in STATIC_ROOT, perhaps `collectstatic` just ignores them, so they never get recognized. – George Cummins Jun 24 '11 at 18:40