- 📖 Complete documentation: https://dj-angles.adamghill.com/
- 📦 Package: https://pypi.org/project/dj-angles/
- Use HTML-like elements in Django templates, e.g.
<dj-partial />
instead of{% include 'partial.html' %}
- Can be sprinkled in as needed to enhance existing Django functionality
- Since it looks like HTML, syntax highlighting mostly "just works"
- Wraps included templates in a custom element for easier debugging and targeted CSS styling
- Support for making components with the Shadow DOM
- Integrates with Django component libraries like django-bird
call
andmodel
template tags to call functions directly from a templatedateformat
filter to use Pythonstrftime
formats instead of PHP when formatting dates- Submit forms via AJAX and swap in the resulting HTML
base.html
<dj-block name='content'> <!-- {% block content %} -->
</dj-block> <!-- {% endblock content %} -->
index.html
<dj-extends parent='base.html' /> <!-- {% extends 'base.html' %} -->
<dj-block name='content'> <!-- {% block content %} -->
<!-- components -->
<dj-partial /> <!-- {% include 'partial.html' %} -->
<dj-include template='partial.html' /> <!-- {% include 'partial.html' %} -->
<!-- evaluate code from the template -->
<dj-call code='slugify("Hello Goodbye")' as='variable_name' /> <!-- {% call slugify("Hello Goodbye") as variable_name %} -->
<dj-model code='Book.objects.filter(id=1)' as='book' /> <!-- {% model Book.objects.filter(id=1) as book %} -->
<!-- AJAX form submission -->
<dj-form action='/submit' method='POST' swap='outerHTML' ajax csrf> <!-- <ajax-form><form action='/submit' method='POST'>{% csrf_token %} -->
<button type='submit'>Submit</button>
</dj-form><!-- </form></ajax-form> -->
<!-- conditional attributes -->
<div dj-if="True"> <!-- {% if True %}<div> -->
If
</div>
<div dj-elif="False"> <!-- {% elif False %}<div> -->
Elif
</div>
<div dj-else> <!-- {% else %}<div> -->
Else
</div> <!-- </div>{% endif %} -->
<dj-verbatim> <!-- {% verbatim %} -->
This is verbatim: {% include %}
</dj-verbatim> <!-- {% endverbatim %} -->
<dj-comment> <!-- {% comment %} -->
this is a comment
</dj-comment> <!-- {% endcomment %} -->
<dj-autoescape-on> <!-- {% autoescape-on %} -->
This is escaped
</dj-autoescape-on> <!-- {% endautoescape %} -->
<dj-autoescape-off> <!-- {% autoescape off %} -->
This is not escaped
</dj-autoescape-off> <!-- {% endautoescape %} -->
<dj-csrf /> <!-- {% csrf_token %} -->
<dj-debug /> <!-- {% debug %} -->
<!-- static helpers -->
<dj-image src='img/django.jpg' /> <!-- <img src="{% static 'img/django.jpg' %}" /> -->
<dj-css href='css/styles.css' /> <!-- <link href="{% static 'css/styles.css' %}" rel="stylesheet" /> -->
</dj-block> <!-- {% endblock content %} -->
To learn how to install and use dj-angles
see the complete documentation at https://dj-angles.adamghill.com/.
There are a growing number of component libraries for Django. A non-complete list:
- Slippers: Build reusable components in Django without writing a single line of Python.
- django-components: Create simple reusable template components in Django.
- django-template-partials: Reusable named inline partials for the Django Template Language.
- django-bird: High-flying components for perfectionists with deadlines.
- django-cotton: Enabling Modern UI Composition in Django.
- django-viewcomponent: Build reusable components in Django, inspired by Rails ViewComponent.
- django-unicorn: The magical reactive component framework for Django ✨.
Emmanuelle Delescolle 💻 |