Django staticfiles extension to download third-party static files
Find a file
2023-01-02 16:03:02 +01:00
staticfiles_downloader Support Django>=2 2023-01-02 15:22:09 +01:00
staticfiles_downloader_test Support Django>=2 2023-01-02 15:22:09 +01:00
.bumpversion.cfg Bump version: 1.0.0 → 1.1.0 2023-01-02 16:03:02 +01:00
.gitignore Support Django>=2 2023-01-02 15:22:09 +01:00
LICENSE Initial commit 2017-06-12 09:34:38 +02:00
manage.py Initial commit 2017-06-12 09:34:38 +02:00
Pipfile Support Django>=2 2023-01-02 15:22:09 +01:00
README.rst Initial commit 2017-06-12 09:34:38 +02:00
setup.cfg Support Django>=2 2023-01-02 15:22:09 +01:00
setup.py Bump version: 1.0.0 → 1.1.0 2023-01-02 16:03:02 +01:00
tox.ini Support Django>=2 2023-01-02 15:22:09 +01:00

-----------------------------
django-staticfiles-downloader
-----------------------------

``django-staticfiles-downloader`` provides ``staticfiles_downloader.DownloaderFinder``,
an extension of ``django.contrib.staticfiles``, which allows you to specify static files
with urls and optionaly checksum in your Django application or Django project settings.
This is particularly useful, when using third-party static files, if you don't want to
either include the files in your project nor depend on CDN in runtime.

The static files are collected with ``python manage.py collectstatic``.

Installation
------------

.. code-block:: bash

    pip install  django-staticfiles-downloader


Configuration
-------------

Add ``staticfiles_downloader.DownloaderFinder`` to ``settings.STATICFILES_FINDERS``:

.. code-block:: python

    STATICFILES_FINDERS = [
        'django.contrib.staticfiles.finders.FileSystemFinder',
        'django.contrib.staticfiles.finders.AppDirectoriesFinder',
        'staticfiles_downloader.DownloaderFinder',
    ]

Define static files urls in your Django application
...................................................

.. code-block:: python

    # your_app/__init__.py
    staticfiles_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',
        ),
    }

Define static files urls in your Django project settings
........................................................

.. code-block:: python

    # your_project/settings.py
    STATICFILES_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',
        ),
    }