Django Static files 404 Django Static files 404 django django

Django Static files 404


This is the working solution for static/media/template access in django for windows,

settings.py

import os.pathSTATIC_ROOT = ''STATIC_URL = '/static/'STATICFILES_DIRS = ( os.path.join('static'), )


For me this turned out to be caused by setting debug to false in settings.py. A workaround is to pass the --insecure switch to runserver, but the real solution is to use a proper web server to serve the static files. See the answers to this question for more details.


If you are running this on a web server are you copying the static files to a public accessible folder? For example:

# web accessible folderSTATIC_ROOT = '/home/your_name/www/mealmate/static/'# URL prefix for static files.STATIC_URL = '/static/'# Additional locations of static filesSTATICFILES_DIRS = (    # location of your application, should not be public web accessible     '/home/your_name/website/mealmate/static',)# List of finder classes that know how to find static files in# various locations.STATICFILES_FINDERS = (    'django.contrib.staticfiles.finders.FileSystemFinder',    'django.contrib.staticfiles.finders.AppDirectoriesFinder',)

Then you can use this post Django static Files and copy the static files to the public accessible folder using manage.py

# --link    Create a symbolic link to each file instead of copying.# --noinput Do NOT prompt the user for input of any kind.#python manage.py collectstatic -link --noinput

Hope that helps!