[Fixed]-Django dev server intermittently fails to serve static files

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

-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?

šŸ‘¤EsseTi

-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.

Leave a comment