Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django dev server intermittently fails to serve static files

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
like image 718
Joe Avatar asked Oct 10 '11 20:10

Joe


People also ask

What is a static file in Django?

In Django, we refer to these files as “static files”. Django provides django.contrib.staticfiles to help you manage them. This page describes how you can serve these static files.

Is it possible to serve files in production using Django?

I am using django 1.5 I am able to serve the files in production because it is being handled at the apache level. Here is my httpd.conf file:

Can Django serve static files with Gunicorn?

Yesterday, I learned during deployment that your Django app when used in combination with gunicorn will refuse to serve static files, do whatever you may. I looked up almost every Stack Overflow answer post on this topic including this, this and this.

How do I serve a static file during development?

If you're Serving static files during development On your settings.pyfile: # Add it on your settings.py file STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static"), # your static/ files folder ] Example: On your root urls.pyfile:


1 Answers

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 ;)

like image 112
jujule Avatar answered Sep 19 '22 03:09

jujule