collectstatic fails to collect admin static files

django static files not found
django static files not working
django admin static files 404
django static files 404
django static files not found in production
django can 't find static files
unable to load static files in django
commanderror(collecting static files cancelled)

I face below error when I run collectstatic and Admin page is served without css.

Error:

IOError: [Errno 2] No such file or directory: u'/usr/local/lib/python2.7/dist-packages/django/contrib/admin/media/img/gis/move_vertex_off.png

Below are the settings.

STATIC_ROOT = '/var/www/mysite/media/'

STATIC_URL = '/static/'

ADMIN_MEDIA_PREFIX = '/static/admin/'

What does this error message mean? The file does exist in the mentioned path.

I assume the problem was due to some installation error. Re-installation of django did not help. Completely re-installed the OS as that was the quicker solution for me and things went fine. But still the root cause continues to be a mystery for me.

STATIC_ROOT = '/var/www/mysite/media/'. STATIC_URL = '/static/'. ADMIN_MEDIA_PREFIX = '/static/admin/'. What does this error message mean? The file  On subsequent collectstatic runs (if STATIC_ROOT isn’t empty), files are copied only if they have a modified timestamp greater than the timestamp of the file in STATIC_ROOT. Therefore if you remove an application from INSTALLED_APPS , it’s a good idea to use the collectstatic --clear option in order to remove stale static files.

By default, collectstatic looks in all locations defined in STATICFILES_DIRS and in the 'static' directory of apps specified by the INSTALLED_APPS setting (see: https://docs.djangoproject.com/en/dev/howto/static-files/ and https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/).

So if you added the admin to your INSTALLED_APPS, this should be fine.

The ADMIN_MEDIA_PREFIX is no longer used in current versions of Django.

Django provides django.contrib.staticfiles to help you manage them. Now we might be able to get away with putting our static files directly in a static file with the same name in a different application, Django would be unable to distinguish​  This not primarily to serve them, but to collect them! The point is that on a productive server, django is not supposed to server static files, this task should be handled by the web server. Check the docs for details. The idea is that you run the command python manage.py collectstatic and django will go through all the paths in STATICFILES_DIRS, collect the static files and put them - exactly! - into the STATIC_ROOT folder.

I solved this problem by running python manage.py collectstatic then adding the following to my Apache config:

Alias /static/admin/ /PATH/TO/MY/PROJECT/static_root/admin/

<Directory /PATH/TO/MY/PROJECT/static_root/admin>
Require all granted
</Directory>

While debugging this, I want to run collectstatic, but that also fails: $ python ./​manage.py collectstatic You have requested to collect static files at  Now I get "Collecting Static files" msg, and importantly rich admin site despite Debug set to FalseSorry the comment policy prevented edit before you commented – harijay Apr 7 '13 at 12:23 1 Ah!

manage.py collectstatic it only moves the admin's .css files located in ../site-​packages/django//css/{..css} and not the css file that I copied over  There are 3 main things to do: set STATIC_ROOT in settings.py. run python2.7 manage.py collectstatic (or python3.5 or python3.6 as appropriate) set up a Static Files entry on the PythonAnywhere Web tab. Optionally, you can also customise STATIC_URL, if you want to use a static URL prefix other than /static/ The STATIC_ROOT variable in settings

Use collectstatic which should collect admin -> static/admin. It will live python manage.py collectstatic open() "/home/user/app/mysyte/static/*.css" failed (13: Permission denied) 1 when you run this command you see your static content. Django will use the first static file it finds whose name matches, and if you had a static file with the same name in a different application, Django would be unable to distinguish between them. We need to be able to point Django at the right one, and the best way to ensure this is by namespacing them.

manage.py collectstatic to put all your static files into STATIC_ROOT . However​, to get the best performance you should proceed to step 3 below and that some of the improvements that WhiteNoise makes to static file handling won't be​  No need for a second one that addresses static/admin/: location /static/ { alias /path/to/static/; } Use collectstatic which should collect admin -> static/admin. It will live under the same location as all the rest of your collected static media. python manage.py collectstatic

Comments
  • I suspect it was the Python installation and configuration of your Django project.
  • @stellarchariot yes. Also I suspect the permissions.
  • @Vino Reinstalling OS? O_O I'm glad for you that it helped.