GithubHelp home page GithubHelp logo

django-vendor-files's Introduction

django-download-vendor-files

Setup

Install using pip:

pip install django-vendor-files

Add vendor_files to INSTALLED_APPS in your Django settings:

INSTALLED_APPS = (
    ...
    'vendor_files',
)

Put the vendor directory in STATICFILES_DIRS in your Django settings:

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'vendor/'), 
    ...
)

Remarks:

  • stay first if you wont load vendor libs first
  • stay second after you own static if you wish ovveride (patch) vendor lib

Add a VENDOR setting to your Django settings, and add your vendor files with URL and SNI, e.g.:

VENDOR = {
    'jquery': {
        'url': 'https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/',
        'js': [
            {
                # final url will be: https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js
                'path': 'jquery.min.js', 
                'sri': 'sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ==',
            }
        ]
    },
    'bootstrap': {
        'url': 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/',
        'js': [
            {
                'path': 'js/bootstrap.min.js',
                'sri': 'sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa',
            }
        ],
        'css': [
            {
                'path': 'css/bootstrap.min.css',
                'sri': 'sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u',
            }
        ]
    }
}

Usage

Put {% load vendor_tags %} at the top of your Django template and the vendor tag , e.g.: {% vendor 'jquery' %}, somewhere in your HTML:

{% load staticfiles %}
{% load vendor_tags %}

<!DOCTYPE html>
<html>
    <head>
        <title>{{ request.site.name }}</title>
        ...
        {% vendor 'jquery' %}
        {% vendor 'bootstrap' %}
    </head>

Extended tags, extract only js or css (can be usefull example for django-compressor):

{% vendor 'jquery' 'js' %}
# or you can use
{% vendor_js 'jquery' %}

{% vendor 'jquery' 'css' %}
# or you can use
{% vendor_css 'jquery' %}

Then, you have 2 options:

  1. To use a CDN, put VENDOR_CDN = True in your Django settings and the vendor tag will be replaced by a <link> or <script> tag using the URLs in the settings.

  2. To use a local copy, put VENDOR_CDN = False (or nothing at all) in your Django settings and the vendor tag will be replaced by a <link> or <script> tag using your STATIC_PATH. The files can be downloaded:

    python ./manage.py download_vendor_files
    

django-vendor-files's People

Contributors

jochenklar avatar mmmcorpsvit avatar

Stargazers

Josh Thomas avatar Jeff Triplett avatar Nikolaus Schlemm avatar Max Schröder avatar  avatar Alejandro Pimentel avatar BethanyG avatar

Watchers

 avatar David Linke avatar Kristin Riebe avatar Gal Matijevic avatar Olaf Michaelis avatar Harry Enke avatar Anastasia Galkin avatar  avatar

django-vendor-files's Issues

Support separate js and css

th for good library, but have same problems:

  1. compress library require separate write css and js

example:

{% compress css %}
  <link rel="stylesheet" href="{% static 'vendor/swiper/swiper-bundle.min.css' %}">
  <link rel="stylesheet" type="text/css" href="{% static 'vendor/video_js/video-js.min.css' %}"/>
  <link rel="stylesheet" type="text/css" href="{% static 'vendor/daterangepicker_3.1.0/daterangepicker.css' %}"/>
{% endcompress %}

.
.
.

{% compress js %}
  <script type="text/javascript" src="{% static 'vendor/video_js/video.min.js' %}"></script>
  <script src="{% static 'vendor/swiper/swiper-bundle.min.js' %}"></script>
{% endcompress %}
  1. how overide some vendors lib after download_vendor_files ?
    static vendors my be first ?

  2. are any way to use some some like
    VENDOR_CDN = 'Auto'
    use when internet present, and not use when no have internet access

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.