'collectstatic' command fails when WhiteNoise is enabled

前端 未结 14 883
别那么骄傲
别那么骄傲 2020-12-08 19:51

I\'m trying to serve static files through WhiteNoise as per Heroku\'s recommendation. When I run collectstatic in my development environment, this happens:

相关标签:
14条回答
  • 2020-12-08 20:14

    I just had this same issue and fixed it by removing this line from my settings file,

    STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
    

    I got this line from the Heroku documentation page...

    0 讨论(0)
  • 2020-12-08 20:21

    For me the fix was simply adding a 'static' folder to the top directory (myapp/static did the trick). If you are setting the STATIC_URL but don't have that directory already created, it will throw an error, even though you aren't using that directory for your static files with whitenoise.

    STATIC_URL = '/static/'
    
    0 讨论(0)
  • 2020-12-08 20:22

    In development Django’s runserver automatically takes over static file handling.

    In most cases this is fine, however this means that some of the improvements that WhiteNoise makes to static file handling won’t be available in development and it opens up the possibility for differences in behaviour between development and production environments. For this reason it’s a good idea to use WhiteNoise in development as well.

    You can disable Django’s static file handling and allow WhiteNoise to take over simply by passing the --nostatic option to the runserver command, but you need to remember to add this option every time you call runserver. An easier way is to edit your settings.py file and add whitenoise.runserver_nostatic to the top of your INSTALLED_APPS list:

    INSTALLED_APPS = [
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    # ...]
    

    Source - http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development

    0 讨论(0)
  • 2020-12-08 20:22

    It worked for me by commenting out the whitenoise in settings.py in production.

    #STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
    #WHITENOISE_ROOT = os.path.join(BASE_DIR, 'staticfiles')
    
    0 讨论(0)
  • 2020-12-08 20:25

    Be sure to check all your settings related to static files, especially making sure the paths are pointing to the right locations. I personally had one of my STATICFILES_DIRS pointing to a wrong path.

    0 讨论(0)
  • 2020-12-08 20:25

    There are two options:

    1. To add the proper link which is in css
    2. By removing the link of file which is not present from css
    0 讨论(0)
提交回复
热议问题