Skip to main content

Django app that caches CDN files for use when coding offline

Project description

This app is to help in those situations where you can’t get on the network but you want to write some Django code. Surround your static CDN references (like jquery and the like) with this template tag and when you turn it on the URLs will be re-written from a local copy.

Installation

In your settings file, add ‘airplane’ to your settings.INSTALLED_APPS field and make the following additions:

import airplane

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, airplane.CACHE_DIR),
)

AIRPLANE_MODE = airplane.BUILD_CACHE
#AIRPLANE_MODE = airplane.USE_CACHE

Now use the airplane tag in your templates

{% load airplanetags %}

<html>
    <head>
        <link rel="stylesheet"
            href="{% airplane 'https://maxcdn.bootstrapcdn.com/bootstrap.min.css' %}">
    </head>
</html>

Change the AIRPLANE_MODE setting to airplane.USE_CACHE and subsequent calls to the {% airplane %} tag will return a reference to the locally cached version.

Settings

Airplane only does something if DEBUG=True and if you have an AIRPLANE_MODE value set to either airplane.BUILD_CACHE or airplane.USE_CACHE. If one of these conditions is not met, the tag simply returns the value passed in.

For example, if DEBUG=False and your template contains:

<link rel="stylesheet"
    href="{% airplane 'https://maxcdn.bootstrapcdn.com/bootstrap.min.css' %}">

Then the above snippet renders as:

<link rel="stylesheet"
    href="https://maxcdn.bootstrapcdn.com/bootstrap.min.css">

When AIRPLANE_MODE is set to airplane.BUILD_CACHE any URLs passed in are fetched and their contents added to a local cache. The default local cache is .airport_cache relative to the base directory of your project.

You can change the location of the cache by setting AIRPLANE_CACHE. The setting accepts either fully qualified paths or paths relative to the project’s base directory.

Once you have cached all the files you are using, switch AIRPLANE_MODE to airplane.USE_CACHE. All URLs are now re-written to point to the contents of the local cache.

Supports

django-airplane has been tested with:

  • Python 2.7, 3.6, 3.7 and Django 1.11

  • Python 3.6, 3.7 and Django 2.1

  • Python 3.6, 3.7 and Django 2.2

Docs

Docs available at: http://django-airplane.readthedocs.io/en/latest/

Source: https://github.com/cltrudeau/django-airplane

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-airplane-0.3.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

django_airplane-0.3.1-py2.py3-none-any.whl (8.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-airplane-0.3.1.tar.gz.

File metadata

  • Download URL: django-airplane-0.3.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.0

File hashes

Hashes for django-airplane-0.3.1.tar.gz
Algorithm Hash digest
SHA256 95f6c4d35e7684fb459c102b5b6380b9b1bb5db802b6aca2834a36f6d079a9ea
MD5 00502e08ee97c04a03b87d38e14f694f
BLAKE2b-256 2d3123a248735147ca222c6cbf795f1a50d5fa0b09dcc3404e8d009e9de7256f

See more details on using hashes here.

File details

Details for the file django_airplane-0.3.1-py2.py3-none-any.whl.

File metadata

  • Download URL: django_airplane-0.3.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.0

File hashes

Hashes for django_airplane-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 38da0476b283e7e5f00b100ea92bfc5f7ac71497fe091c7351aedb5f9ecc7788
MD5 544fe6aae41d27d1a463a0573f47d07e
BLAKE2b-256 bc91a0d9a72f6a30096372e373ea4f7a554ecb352d7cbc0261c57a9e3cb9b287

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page