Skip to content

Add Django app to simplify integration into Django projects

Django apps have a special structure where resources should be "namespaced" in a subdirectory based on the app name, where e.g. {% include "appname/resource.html" %} maps to templates/appname/resource.html. This applies to both templates and static files.

  1. The solution for static files is simpler, the app can simply inject its locations (and prefixes) to the STATICFILES_DIRS list. This works for prebuilt CSS files, the app does not handle live building of SASS files. A subcommand for manage.py is provided for convenience.

  2. For templates we can provide a custom loader, but downstream projects will need to add it into their configuration manually (see below).

Overall, this allows to integrate archlinux-common-style in a Django project with a simple configuration:

INSTALLED_APPS = [
    ...
    "archlinux_common_style.django",
    ...
]

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "OPTIONS": {
            "loaders": [
                (
                    "django.template.loaders.cached.Loader",
                    [
                        "django.template.loaders.filesystem.Loader",
                        "django.template.loaders.app_directories.Loader",
                        "archlinux_common_style.django.template_loader.Loader",
                    ],
                ),
            ],
            ...
        },
        ...
    },
    ...
]

Note that the name in apps.py assumes that Django can import the archlinux_common_style.django module in the project where this app is used. This can be achieved by having archlinux-common-style as a git submodule in the project, but with the non-canonical name with underscores instead of dashes: archlinux_common_style. Alternatively, we could drop the prefix, solve the name clash with the main django module and require modifying sys.path in the project's settings.

Edited by Jakub Klinkovský

Merge request reports