Skip to main content

A Django package to include alpine.js to your django project.

Project description

Overview

django-alpine is a Django package that simplifies the integration of Alpine.js into your Django project. It handles the automatic downloading and inclusion of Alpine.js in your Django project’s static files, ensuring a smooth setup with minimal configuration.

Features

  • Automatically downloads the latest Alpine.js from a CDN into your static/js directory.

  • Ensures Alpine.js is included in your Django templates with a simple template tag.

  • Integrates seamlessly with Django’s INSTALLED_APPS.

Installation

### Prerequisites

Ensure your environment meets the following requirements:

  • Python: 3.10 or higher

  • Django: 4.2 or higher

### Steps

  1. Install the package via pip:

    pip install django-alpine
  2. Add django_alpine to your INSTALLED_APPS in settings.py:

    INSTALLED_APPS = [
        ...,
        'django_alpine',
    ]
  3. Collect static files to ensure the downloaded alpine.js is included in your static files directory:

    python manage.py collectstatic

Usage

Automatic Alpine.js Download

Once you add django_alpine to INSTALLED_APPS, the app’s ready method will automatically download the latest version of Alpine.js into your static files directory (static/js/alpine.js).

If the file already exists, it won’t download it again unless the version has changed. This ensures your static files are kept up-to-date without redundant downloads.

Template Integration

Using the Template Tag

The package provides a custom template tag to include Alpine.js in your HTML templates. Use the {% load alpine_tags %} tag to include Alpine.js dynamically.

  1. Load the template tags in your HTML file:

    {% load alpine_tags %}
  2. Add the include_alpine tag in the <head> or before your closing <body> tag:

    {% include_alpine %}

This will inject the following <script> tag into your HTML:

<script src="/static/js/alpine.js" defer></script>

Manual Script Inclusion (Optional)

If you prefer to include the Alpine.js script tag manually, ensure the static files have been collected using python manage.py collectstatic. Then, include it directly:

<script src="{% static 'js/alpine.js' %}" defer></script>

Updating Alpine.js

To update Alpine.js to the latest version:

  1. Remove the existing file (static/js/alpine.js) manually or via a script.

  2. Restart your Django server. The django_alpine app will detect the missing file and download the latest version.

Uninstallation

To remove django-alpine:

  1. Uninstall the package:

    pip uninstall django-alpine
  2. Remove django_alpine from your INSTALLED_APPS in settings.py.

  3. (Optional) Delete the static/js/alpine.js file.

Development and Contribution

Contributions are welcome! Follow these steps to contribute:

  1. Clone the repository:

    git clone https://github.com/ProKelly/django-alpine.git
  2. Create a virtual environment and install dependencies:

    python -m venv env
    source env/bin/activate  # On Windows: .\env\Scripts\activate
    pip install -r requirements.txt
  3. Test your changes by running the Django project locally.

License

django-alpine is licensed under the BSD License. See the LICENSE file for more details.

Troubleshooting

Error: Alpine.js Not Found

  • Ensure python manage.py collectstatic has been run.

  • Verify that django_alpine is added to your INSTALLED_APPS.

Error: Static Files Not Loading

  • Confirm your STATICFILES_DIRS and STATIC_ROOT settings are correctly configured.

  • Ensure the web server serving your application is configured to serve static files.

Contact

For further support, feel free to contact:

This documentation ensures you can effectively integrate and use django-alpine in your projects. Happy coding!

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_alpine-0.1.4.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

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

django_alpine-0.1.4-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file django_alpine-0.1.4.tar.gz.

File metadata

  • Download URL: django_alpine-0.1.4.tar.gz
  • Upload date:
  • Size: 23.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.0 CPython/3.12.6

File hashes

Hashes for django_alpine-0.1.4.tar.gz
Algorithm Hash digest
SHA256 18bb6275f57e42ea13ec38faaa5782bec723d4e524e0c64c799140d9cd475586
MD5 d39f25198c3e6bab5130d73ac2636974
BLAKE2b-256 37c9a601e7cdb56627733de91840daeab8fb6f090e822cd3e4910450d47e3cc8

See more details on using hashes here.

File details

Details for the file django_alpine-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: django_alpine-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.0 CPython/3.12.6

File hashes

Hashes for django_alpine-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 423f2d11519ecede45a4d9d890d391c757bee259defcfa4435db8f0d72984893
MD5 c2b2fb77a2dda90a255236d1ece704fa
BLAKE2b-256 83bbd8db1bf23bc80f19a9ff14d2e647937674dc68b898ef2893a89e683a7959

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