我可以强制Django静态文件在Debug = True时在本地加载散列文件名吗?

时间:2022-11-18 23:03:46

I'm using STATICFILES_STORAGE = 'offsite_storage.storages.CachedS3FilesStorage' to store all my static files on S3. On my localhost it's trying to load assets using staticfiles from my S3 location without the hashed name. But my STATICFILES_STORAGE provider (django-offsite-storage) only uploads the hashed name version to S3. I want to keep DEBUG=True on my local machine, but I want my S3 assets to load the hashed filename version.

我正在使用STATICFILES_STORAGE ='offsite_storage.storages.CachedS3FilesStorage'来存储我在S3上的所有静态文件。在我的本地主机上,它尝试使用来自我的S3位置的静态文件加载资源而不使用散列名称。但是我的STATICFILES_STORAGE提供程序(django-offsite-storage)只将散列名称版本上传到S3。我想在我的本地机器上保持DEBUG = True,但我希望我的S3资产加载散列文件名版本。

Is there anyway to do this?

反正有没有这样做?

1 个解决方案

#1


1  

You can use a workaround. Create a file called local_settings.py and set a different storage. After, in your settings import the module:

您可以使用变通方法。创建名为local_settings.py的文件并设置其他存储。之后,在您的设置中导入模块:

try:
    from local_settings import *
except ImportError:
    pass

Keep that file only in the local version of your site.

仅将该文件保留在站点的本地版本中。

#1


1  

You can use a workaround. Create a file called local_settings.py and set a different storage. After, in your settings import the module:

您可以使用变通方法。创建名为local_settings.py的文件并设置其他存储。之后,在您的设置中导入模块:

try:
    from local_settings import *
except ImportError:
    pass

Keep that file only in the local version of your site.

仅将该文件保留在站点的本地版本中。