下载第三方静态文件的django static files扩展
django-staticfiles-downloader的Python项目详细描述
django-staticfiles-downloader提供staticfiles_downloader.DownloaderFinder, django.contrib.staticfiles的扩展名,允许您指定静态文件 在django应用程序或django项目设置中使用url和可选的校验和。 在使用第三方静态文件时,如果您不想 要么在项目中包含这些文件,要么在运行时依赖cdn。
静态文件是用python manage.py collectstatic收集的。
安装
pip install django-staticfiles-downloader
配置
将staticfiles_downloader.DownloaderFinder添加到settings.STATICFILES_FINDERS:
STATICFILES_FINDERS=['django.contrib.staticfiles.finders.FileSystemFinder','django.contrib.staticfiles.finders.AppDirectoriesFinder','staticfiles_downloader.DownloaderFinder',]
在django应用程序中定义静态文件url
# your_app/__init__.pystaticfiles_urls={# use only url'my_app/js/jquery-3.2.1.min.js':'https://code.jquery.com/jquery-3.2.1.min.js',# or use url and checksum'my_app/js/jquery-2.2.4.min.js':('https://code.jquery.com/jquery-2.2.4.min.js','sha384','rY/jv8mMhqDabXSo+UCggqKtdmBfd3qC2/KvyTDNQ6PcUJXaxK1tMepoQda4g5vB',),}
在django项目设置中定义静态文件url
# your_project/settings.pySTATICFILES_URLS={# use only url'js/jquery-3.2.1.min.js':'https://code.jquery.com/jquery-3.2.1.min.js',# or use url and checksum'js/jquery-2.2.4.min.js':('https://code.jquery.com/jquery-2.2.4.min.js','sha384','rY/jv8mMhqDabXSo+UCggqKtdmBfd3qC2/KvyTDNQ6PcUJXaxK1tMepoQda4g5vB',),}