0

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?

Tom Carrick
  • 6,349
  • 13
  • 54
  • 78
Zain Khan
  • 3,753
  • 3
  • 31
  • 54
  • What is your STATIC_URL set to and what url for example are you using to access some media? – jdi Dec 16 '11 at 07:12
  • STATIC_URL = '/static/' and localhost/static/ is being used – Zain Khan Dec 16 '11 at 07:18
  • Are you sure you are testing this against the development server and not apache, etc? The static ports and all that shouldnt matter from the dev server and your url should be relative or dynamic. Try /static/file.css I would expect a port in that absolute path unless you are running it on 80 – jdi Dec 16 '11 at 07:36
  • 2
    What app are you using to serve static? django-staicfiles? Then what is `STATIC_SERVE_PORT`? Never heard about this setting, and google gives only one link — this question. – DrTyrsa Dec 16 '11 at 07:39
  • @jdi I am running my django development server by **sudo python manage.py runserver 0.0.0.0:80** therefore I do not have to specify the port. Secondly, the file.css link is also returning 404 – Zain Khan Dec 16 '11 at 07:45
  • @DrTyrsa: _django-staticfiles_ is not in the list of _requirements.txt_ and the settings_local file was provided by the client. Sorry but I am not sure about it either – Zain Khan Dec 16 '11 at 07:48
  • @Zulaikha Do you have a record about `static` in your root `urls.py`? – DrTyrsa Dec 16 '11 at 07:52
  • @Zulaikha: I think DrTyrsa is right. There must be a missing url. If that is the case try using **urlpatterns += patterns('', url(r'^media/(?P.*)$', 'django.views.static.serve', { 'document_root': settings.MEDIA_ROOT, }), )** – Zain Khan Dec 16 '11 at 08:02
  • @DrTyrsa: **NO** there is nothing related to **STATIC** in the root urls.py file. – Zain Khan Dec 16 '11 at 08:02
  • @mangobug: I tried using this urlpattern but still does not work – Zain Khan Dec 16 '11 at 08:03
  • @Zulaikha Then why do you think static files should load? – DrTyrsa Dec 16 '11 at 08:11

3 Answers3

1

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

jdi
  • 90,542
  • 19
  • 167
  • 203
0

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
DrTyrsa
  • 31,014
  • 7
  • 86
  • 86
  • From the question it doesn't look like they actually have any static file serving feature. So it's not a "rewrite", it's a "write". – S.Lott Dec 19 '11 at 03:12
0

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,
    }),

)

Zain Khan
  • 3,753
  • 3
  • 31
  • 54