pythondjangoservercollectstatic

Why is collectstatic not copying all my directories?


Currently working on deployment for my django website. Im trying to get my static files working so obviously I used this command: python manage.py collectstatic. Once finished running it prints 119 files copied... I thought this was working until I cd'd into the newly created static directory and didn't find my css folder. Weirdly enough, I did see the admin folder. Once I saw this, I deleted my static folder entirely and attempted to directly copy the static folder using scp. I did this and all of my other folders (css, uploads, etc. And also the admin folder) appeared. I tried to collectstatic now with all of the folders there only to find out when I do that, it deletes all of my folders except for the admin folder. When I start the website up using the runserver command. There is no css on my homepage but there is in the admin page.

This is how everything looks like in the finder.

(projectname) ——— env
              ——— excelsite
              ——— pages
              ——— templates
              ——— (settings folder)
              ——— static ——— css, uploads, admin
              ——— manage.py
              ——— db.sqlite3

This is my settings.py:

STATIC_ROOT = "/home/alexholst/excelsite/static"
STATIC_URL = '/static/'

#STATICFILES_DIRS = ("/home/alexholst/excelsite/static",)

#STATICFILES_DIRS = (
#    os.path.join('static'),
#    'static',
#)

Any help is very much appreciated!!

Thanks in advance!


Solution

  • You need to configure in settings.py

    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, "static"),
        '/var/www/static/',
    ]
    

    And add your app's static directory there.

    See https://docs.djangoproject.com/en/3.0/howto/static-files/