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.

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.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

django_airplane-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for django-airplane-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4dff2cad2bf9bb9ad65f3ddb0c85127f1a54079e4d96d0a321d3ca5fe231e8b4
MD5 e6e25d3d5ac7a923544ba71e30b4456b
BLAKE2b-256 7c780a2cc429164fc0dc5150ef0f6aae7a1a08b43bf5dd47c2ed2d7b61404a7b

See more details on using hashes here.

File details

Details for the file django_airplane-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_airplane-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 625bb146b5a424ff5ecaeeb08be8afdf36da181527ed81122e101a3dc748fcae
MD5 d49dc4f44c32f73d56ebaf7927c7f21d
BLAKE2b-256 9c4cc914fb217a3e87f6e64c481a00373a6695dcaf17b7b322d33bc83fda743b

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