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:
-
To use a CDN, put
VENDOR_CDN = Truein your Django settings and the vendor tag will be replaced by a<link>or<script>tag using the URLs in the settings. -
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 yourSTATIC_PATH. The files can be downloaded:python ./manage.py download_vendor_files
Metadata
Release files for django-vendor-files 0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-vendor-files-0.3.tar.gz | 4.3 kB | Without provenance | Details for django-vendor-files-0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_vendor_files-0.3-py3-none-any.whl | Python 3 | none | any | Details for django_vendor_files-0.3-py3-none-any.whl |
Total release size: 9.6 kB
Release files / django-vendor-files-0.3.tar.gz
| Download URL | django-vendor-files-0.3.tar.gz |
|---|---|
| Size | 4.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f19af52293140d8aee983cc5523e45810cf37398e332d6b6d0fee034c809c97
|
|
BLAKE2b-256 checksum How to use checksums |
174130e969deff2b010538952c9fed971b8d88f49aa140a7a70edfffd6e63146
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2
|
Release files / django_vendor_files-0.3-py3-none-any.whl
| Download URL | django_vendor_files-0.3-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e404a6aef9daf274d851fae5db03d9a02e58722ef1fd50cd77bb19c9b5367312
|
|
BLAKE2b-256 checksum How to use checksums |
53694f73bd63aed765ed0e4245f10bc6305db04efdf8f11ca40699c499c99c20
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.2
|
Security for django-vendor-files 0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.