Django Staticfiles Noimport
django-staticfiles-import exists to allow Django's
collectstatic management command to run with the
bare minimum of environment variables so it can be
run inside a docker build step such that the produced
container is self-contained.
This approach allows typical runtime initialization to
verify all required runtime environment variables are
defined and provides an alternative entrypoint for just
the collectstatic and findstatic commands.
Specifically, this project allows for Django apps
with static/ directories that expect you to use the
enabled-by-default AppDirectoriesFinder.
Requirements & Constraints
Utilizing this package requires accepting a handful of constraints that are acceptable in our environment:
- Static assets will be served at the same path in all
environments (i.e.
STATIC_URLdoesn't vary per environment.) - Django "apps" may not manipulate any static file handling behaviors during app initialization.
INSTALLED_APPSmust reference app names as strings, as opposed to importing anAppConfigdirectly.
Setup
- Ensure you have an
os.environ-agnostic settings module.- This may be achieved by creating a simple
settings/apps.pymodule that is imported from your primary settings with glob syntax like:from .apps import *and asettings/static.pythat imports it as well. - Somewhere in that settings chain you must define
SECRET_KEYwhich is the one required non-staticfiles related setting.
- This may be achieved by creating a simple
- Use the provided
staticfiles_noimport.finders.AppDirectoriesNoImportFinderin yourSTATICFILES_FINDERSsettings. (See included example.) - Use
collectstaticandfindstaticdirectly without using the typicalmanage.pyentrypoint. You'll need to inject your static-specific settings (e.g.,DJANGO_SETTINGS_MODULE=settings.static) for things to work as expected.
Example Usage
# settings/apps.py
INSTALLED_APPS = (
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.admin",
...
...
"yourappone",
"yourapptwo",
)
# settings/static.py
from .apps import *
STATIC_ROOT = "/static/foobar/"
STATIC_URL = "/static/foobar/"
STATICFILES_DIRS = (
"/some/resolved/path/static",
)
STATICFILES_FINDERS = (
"django.contrib.staticfiles.finders.FileSystemFinder",
"staticfiles_noimport.finders.AppDirectoriesNoImportFinder"
)
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
Running collectstatic:
$ DJANGO_SETTINGS_MODULE=myproject.settings.static collectstatic
Metadata
Release files for django-staticfiles-noimport 0.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-staticfiles-noimport-0.9.tar.gz | 3.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_staticfiles_noimport-0.9-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.3 kB
Release files / django-staticfiles-noimport-0.9.tar.gz
| Download URL | django-staticfiles-noimport-0.9.tar.gz |
|---|---|
| Size | 3.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ce278c1b553637137303a560b01870879825782df716d3f1d3cb0f7ac11a821b
|
|
BLAKE2b-256 checksum How to use checksums |
6f08c02d0ffe518e83d836ee6f292fb14d078d7e51367f333dd9d6a1e3265e4f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.8
|
Release files / django_staticfiles_noimport-0.9-py3-none-any.whl
| Download URL | django_staticfiles_noimport-0.9-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2914d6eafcd12a2ff72b112b55645ef6b5e99a34298927331cd6ec327bb37bfa
|
|
BLAKE2b-256 checksum How to use checksums |
8452c8888fccb4b415cae0b3ac47f286e5164994865eacefbb2d419fbfdc3737
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.6.8
|