Package: django-airplane
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.InstallationIn your settings file, add ‘airplane’ to yoursettings.INSTALLED_APPSfield:INSTALLED_APPS=(...'airplane',)Also in settings, make the following additions:importairplaneSTATICFILES_DIRS=(airplane.cache_path(),)AIRPLANE_MODE=airplane.BUILD_CACHE#AIRPLANE_MODE = airplane.USE_CACHE#AIRPLANE_MODE = airplane.AUTO_CACHENow use theairplanetag in your templates{% load airplanetags %}<html><head><linkrel="stylesheet"href="{% airplane 'https://maxcdn.bootstrapcdn.com/bootstrap.min.css' %}"></head></html>Change theAIRPLANE_MODEsetting toairplane.USE_CACHEand subsequent
calls to the{% airplane %}tag will return a reference to the locally
cached version.SettingsAirplane only does something ifDEBUG=Trueand if you have anAIRPLANE_MODEvalue set toairplane.BUILD_CACHE,airplane.USE_CACHE, orairplane.AUTO_CACHE.  If one of these
conditions is not met, the tag simply returns the value passed in.For example, ifDEBUG=Falseand your template contains:<linkrel="stylesheet"href="{% airplane 'https://maxcdn.bootstrapcdn.com/bootstrap.min.css' %}">Then the above snippet renders as:<linkrel="stylesheet"href="https://maxcdn.bootstrapcdn.com/bootstrap.min.css">WhenAIRPLANE_MODEis set toairplane.BUILD_CACHEany URLs passed in
are fetched and their contents added to a local cache.  The default local
cache is.airport_cacherelative to the base directory of your project.You can change the location of the cache by settingAIRPLANE_CACHE.  The
setting accepts either fully qualified paths or paths relative to the
project’s base directory.# settings.pyAIRPLANE_CACHE=/foo/bar/cache# fully qualified# orAIRPLANE_CACHE=my_cache# relative to settings.BASE_DIR# or nothing, defaults to settings.BASEDIR + '.airplane_cache'Once you have cached all the files you are using, switchAIRPLANE_MODEtoairplane.USE_CACHE.  All URLs are now re-written to point to the contents
of the local cache.Alternatively, you can setAIRPLANE_MODEtoairplane.AUTO_CACHEand
the first call will cache the file and subsequent calls will use the cached
copy.CommandsThe following django commands come with airplane.airinfo$./manage.pyairinfoCachemode:AUTO_CACHECachedirectory:/Users/foo/sample_site/.airplane_cacheCachecontents:https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.cssThis command takes no arguments and displays information about the cache. The
current mode, the path of the directory and any items cached inside are shown.aircache./manage.pyaircachehttps://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.cssThis command takes a single URL as an argument and caches the contents of the
URL.Schemaless URLsAs airplane is a template tag library, it doesn’t have access to the request
object at execution. In order to allow schemaless URLs, the code makes the
assumption that the schema is “https” if it is not given in the URL.LimitationsThe intent of this library is to help you when you’re using the Django
debugging server and in a situation where you can’t easily get to the network.
Cached files are served using the django static server code, which means you
are limited by what kinds of files it can serve. The static server makes
guesses on the mimetype of the file based on file extensions. Airplane naively
copies the extension of the file so the cached file has the same ending. This
means URLs with weird extensions or those which static serve cannot guess at
mimetype, will cause problems. It is not recommended to use django-airplane
with files that don’t end in typical extensions such as “.css”, “.js”, “.jpg”,
“.png” or “.gif”.Supportsdjango-airplane has been tested with:Python 3.8-3.11 and Django 4.1Python 3.8-3.11 and Django 4.2Older versions tested against Django 2.2 and 3.2, nothing has changed since
then that should break, but these are no longer test targetsDocsDocs available at:http://django-airplane.readthedocs.io/en/latest/Source:https://github.com/cltrudeau/django-airplane