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
Install the package via pip:
pip install django-alpineAdd django_alpine to your INSTALLED_APPS in settings.py:
INSTALLED_APPS = [ ..., 'django_alpine', ]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.
Load the template tags in your HTML file:
{% load alpine_tags %}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:
Remove the existing file (static/js/alpine.js) manually or via a script.
Restart your Django server. The django_alpine app will detect the missing file and download the latest version.
Uninstallation
To remove django-alpine:
Uninstall the package:
pip uninstall django-alpineRemove django_alpine from your INSTALLED_APPS in settings.py.
(Optional) Delete the static/js/alpine.js file.
Development and Contribution
Contributions are welcome! Follow these steps to contribute:
Clone the repository:
git clone https://github.com/ProKelly/django-alpine.gitCreate a virtual environment and install dependencies:
python -m venv env source env/bin/activate # On Windows: .\env\Scripts\activate pip install -r requirements.txtTest 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:
Name: Anye Prince Kelly
Email: firstanye@gmail.com
Repository: GitHub Repository
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18bb6275f57e42ea13ec38faaa5782bec723d4e524e0c64c799140d9cd475586
|
|
| MD5 |
d39f25198c3e6bab5130d73ac2636974
|
|
| BLAKE2b-256 |
37c9a601e7cdb56627733de91840daeab8fb6f090e822cd3e4910450d47e3cc8
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
423f2d11519ecede45a4d9d890d391c757bee259defcfa4435db8f0d72984893
|
|
| MD5 |
c2b2fb77a2dda90a255236d1ece704fa
|
|
| BLAKE2b-256 |
83bbd8db1bf23bc80f19a9ff14d2e647937674dc68b898ef2893a89e683a7959
|