Question

My django project contains a folder STATIC in which there are it's child folders css, images, js and swf. My web-site can not locate these files raising a 404 in the development server running on the terminal.

I have a settings_local.py file in which I have set the path such as (running on ubuntu 11.04)

STATIC_ROOT = '/home/zulaikha/dust.bin/my_project/static/'
STATIC_SERVE_PORT = 80

The sample settings-local.py file from the client suggest suggest so

# static root
STATIC_ROOT = 'C:/Program Files (x86)/XAMPP/htdocs/static'
STATIC_SERVE_PORT = 8080

I have seen some similar issues but all regard STATICFILES which I read was introduced in Django 1.3 Where am I wrong and how can I correct myself?

Was it helpful?

Solution 3

In the simplest form, this is the solution to the problem. In project urls.py include the following lines

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

)

OTHER TIPS

If you are indeed using django 1.2 then you must install django-staticfiles. If you do not see it in the included requirements.txt from your client then he either did not freeze it out into the file, or was not using that feature and instead was just pointing at it via apache or another production server.

Follow these instructions from the docs. Specifically the basic section: https://docs.djangoproject.com/en/dev/howto/static-files/

You will need to add staticfiles to your installed app. You should also not need to manually add a url since the django should do it automatically with the runserver command.

Also verify that it works locally first by not running with sudo or a custom ip and port

According to your comments there are two options here:

  1. Contact the programmer who wrote the code and ask him.
  2. Rewrite static serving logic with
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top