14

In my development environment I'm getting intermittent failures for serving static files (js scripts and css). In the error console in Chrome I get 404s. But if I refresh on those items, or visit the URLs directly, they're served up fine.

This is annoying.

Example:

GET http://127.0.0.1:8000/static/js/editor/xyz.js?v=1 404 (NOT FOUND)

but if I visit that URL directly fine. And if I refresh the page a few times, it will work again.

Any ideas?

Chrome 14.0.835.202

Django==1.3
Fabric==1.0.1
Jinja2==2.5.5
PIL==1.1.7
Pygments==1.3.1
South==0.7.3
Sphinx==1.0.5
boto==2.0
chunks==0.1
django-devserver==0.2.1
django-pagination==1.0.7
django-sorting==0.1
django-storages==1.1.3
docutils==0.8
gunicorn==0.12.1
ipython==0.10.1
paramiko==1.7.6
pep8==0.6.1
psycopg2==2.2.2
pycrypto==2.0.1
python-dateutil==1.5
python-memcached==1.45
wsgiref==0.1.2
Joe
  • 46,419
  • 33
  • 155
  • 245

3 Answers3

2

The dev server is single-threaded so if something keeps waiting, it blocks every request.

I usualy work with the django concurent dev server which is multi-threaded and works much better. Also it is very fast and easy to setup ;)

jujule
  • 11,125
  • 3
  • 42
  • 63
  • This has stopped happening for me, it is frustrating. I have not updated Django on the project... strange. – Joe Jan 14 '12 at 00:15
  • @Thomas: maybe chrome do something special? It probably should be confirmed with other browsers. – spinus Apr 11 '13 at 10:29
  • @Joe: Have you 404 in your django runserver console log? You may also increase debugging level and then check if a problems appears again. – spinus Apr 11 '13 at 10:30
-1

it might depends on your setup. what did you do for the static? what's the settings? did you do the collect static? try this in case

however, about serving static files in development:

Warning This will only work if DEBUG is True.

That’s because this view is grossly inefficient and probably insecure. This is only intended for local development, and should never be used in production.

from here

can't you just supply the static files in another server?

Community
  • 1
  • 1
EsseTi
  • 4,079
  • 5
  • 36
  • 63
  • I'm sorry this was so long ago I can't remember. I think it stopped happening so I stopped worrying about it. – Joe Mar 05 '13 at 16:24
  • It's normal to serve static files from the dev server. It's typical for development. I didn't say this happens in production. – Joe Mar 05 '13 at 16:38
-1

After reading all answers if still anyone having this problem then ... As per Django nature you don't need to do anything to serve static files just your settings file should have proper configuration as follows:

STATIC_URL = '/static/'

STATICFILES_DIRS = (
    # **THIS IS USED WHEN YOUR STATIC FILES ARE IN SOME OTHER FOLDER ALSO**

    # Put strings here, like "/home/html/static" or "C:/www/django/static".
    # Always use forward slashes, even on Windows.

    # Don't forget to use absolute paths, not relative paths.

    FOLDER_NAME, 
)

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'django.contrib.staticfiles.finders.DefaultStorageFinder',
)

INSTALLED_APPS = (
    # other apps
    'django.contrib.staticfiles',
)

But if still you face problem put this into your urls.py:

(r'^(path of your file)$', 'django.views.static.serve' , {'document_root': 'PROJECT_ROOT_DIR' + "path to the static folder"}),

Above URL will serve for static files whether they are JS files or CSS or images.

In case of production server you don't need this.

Then run: python manage.py collecstatic.

Hope this helps.

Rafa Viotti
  • 9,998
  • 4
  • 42
  • 62
Manuj Rastogi
  • 347
  • 1
  • 11
  • Sorry this doesn't help. As per my question, this is an intermittent problem. Meaning: it works most of the time. – Joe Jun 14 '13 at 12:59
  • Thats what i wrote that by default you dont need to do anything to serve static files in your development environment. But if your facing it at irregular intervals , you can tweak it by this . hope this helps .. – Manuj Rastogi Jun 14 '13 at 13:03
  • Thank you, but I don't think this is the issue. It's probably around socket handling a bit lower down (i.e. to do with the Django code rather than the configuration of the file serving). – Joe Jun 14 '13 at 13:55