Skip to main content

Use webpack with your multi-page, multi-lingual django webapp

Project description

django-webpack-pages

PyPI version Code style: black

Use webpack with your multi-page, multi-lingual django webapp.

This project is based on django-webpack-loader which handles the connection to webpack. Consider using webpack-critical-pages as well if you are interested in speedups.

Put the following in your settings file:

WEBPACK_PAGES = {
    "CRITICAL_CSS_ENABLED": True,
    "ROOT_PAGE_DIR": osp.join(BASE_DIR, "pages"),
    "STATICFILE_BUNDLES_BASE": "bundles/{locale}/",  # should end in /
}

STATICFILES_FINDERS = (
    "webpack_pages.pageassetfinder.PageAssetFinder",
    # ... and more of your choosing:
    "django.contrib.staticfiles.finders.FileSystemFinder",
    "django.contrib.staticfiles.finders.AppDirectoriesFinder",
)

# configure the loaded page directories and add the WebpackExtension
TEMPLATES = [
    {
        "BACKEND": "django_jinja.backend.Jinja2",
        "DIRS": [osp.join(BASE_DIR, "templates"), osp.join(BASE_DIR, "pages")]
        + [osp.join(BASE_DIR, app, "pages") for app in GRAZBALL_APPS]
        + [osp.join(BASE_DIR, app, "components") for app in GRAZBALL_APPS],
        "APP_DIRS": True,
        "OPTIONS": {
            # ...
            "extensions": [
                # ...
                "webpack_pages.jinja2ext.WebpackExtension",
            ],
        }
    }
]

Using webpack_loader.contrib.pages you can register entrypoints for corresponding pages in templates.

At the top of your individual page, do:

{% extends "layout.jinja" %}
{% do register_entrypoint("myapp/dashboard") %}

In the layout's (base template's) head, place the following:

<!DOCTYPE html>
{% do register_entrypoint("main") %}
<html lang="{{ LANGUAGE_CODE }}">
<head>
  ...
  {{ render_css() }}
</head>
<body>
  ...
  {{ render_js() }}
</body>

This will load the registered entrypoints in order (main, then myapp/dashboard) and automatically inject the webpack-generated css and js. It also supports critical css injection upon first request visits.

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_webpack_pages-0.2.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_webpack_pages-0.2.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file django_webpack_pages-0.2.0.tar.gz.

File metadata

  • Download URL: django_webpack_pages-0.2.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.3 Linux/6.14.0-36-generic

File hashes

Hashes for django_webpack_pages-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d126f7d5ff368e31375bc55e6bd5c860d2556fbe61df3e66f6a91fdf8ce66f88
MD5 2511cc86c7fa1595f00fed889b7d671d
BLAKE2b-256 ccf612cf4ef2ed8df0c41875c5612eedb5f981b24f2487d6e42e9cd705974533

See more details on using hashes here.

File details

Details for the file django_webpack_pages-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: django_webpack_pages-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.13.3 Linux/6.14.0-36-generic

File hashes

Hashes for django_webpack_pages-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55b20fd19ac7914c1a5b2873a3bd294151f124ee66f7dd55d71b0996f4ad6740
MD5 cf78c400425436525a6bae74ce1936dd
BLAKE2b-256 d2edef3d84e2c9ee01a0b88dfe2b1624ba2d3e40fa04c88a4c2fcd3d0d6bbb36

See more details on using hashes here.

Supported by

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