why collectstatic won't copy my static files?

前端 未结 7 1873
野的像风
野的像风 2021-02-05 10:07

I have MyApp/static/MyApp directory

When I run ./manage.py collectstatic, I expect the MyApp directory be copied to STATIC_ROOT but it doesn\'t

I have Downloaded

相关标签:
7条回答
  • 2021-02-05 10:22

    That just happened to me and I accidentally put the app's static files directory in the .gitignore file. So on my local machine it got collected just fine, but in production the static files were actually missing (gitignored).

    0 讨论(0)
  • 2021-02-05 10:28

    I was under the impression the comparison would be content based. It turned out to be date based. So, don't mess with your files after collecstatic.

    0 讨论(0)
  • 2021-02-05 10:29

    One Quick work-around, although this does not fix it or explain WHY it's happening, is to:

    1. go to your project's file directory & rename your project's 'static' folder to something else like 'static-old'
    2. create a new,empty folder called 'static' in your project directory
    3. now if you run python manage.py collectstatic it will see that nothing is in your static folder and will copy ALL static files over.
    0 讨论(0)
  • 2021-02-05 10:33

    This happened to me because while investigating a bug occurring on certain dates, changed my computer date and time.

    Hence it disturbed things like collectstatic, and also my browser history.

    Don't change your computer date and time.

    0 讨论(0)
  • 2021-02-05 10:34

    just do this and make the naming convention same

    STATIC_URL = '/static/'
    STATICFILES_DIRS = [
        os.path.join(BASE_DIR, 'static')
    ]
    STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
    

    static directory contains all off your project assets

    assets directory will create automatic when u run this cmd

    python3 manage.py collectstatic
    

    this will copy all static folder content into assets folder

    hope this helps :)

    0 讨论(0)
  • 2021-02-05 10:40

    if you have setup everything properly for static and you are using nginx then enter this command

    sudo nginx -t
    

    You will see error why your static files aren't being served and fix that specific error

    In my case I gave wrong path in my nginx config

    location /static {
            root /home/ubuntu/myproject/app/static/;
        }
    
    0 讨论(0)
提交回复
热议问题