A Django template backend for Liquid.
Project description
A Django template backend for Liquid. Render Liquid templates in your Django apps.
Installing
Install and update using pip:
$ python -m pip install -U django-liquid
Quick Start
If you’re already familiar with configuring Django for Jinja2, Liquid works in almost exactly the same way. Just with less options. Simply set BACKEND to django_liquid.liquid.Liquid.
Add configuration for the Liquid template engine to your Django project’s settings.py file. Starting with the default TEMPLATE configuration after running django-admin startproject mysite, basic Liquid configuration would look like this.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
{
'BACKEND': 'django_liquid.liquid.Liquid',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {},
},
]
When APP_DIRS is True, Liquid engines look for templates in the liquid subdirectory of installed applications.
OPTIONS are passed to the liquid.Environment constructor. The default Environment is configured as follows.
autoescape: True
loader: a FileSystemLoader configured for DIRS and APP_DIRS
undefined: DebugUndefined if settings.DEBUG else Undefined
Render Liquid templates from your app views just like any other Django template backend.
from django.shortcuts import render
def index(request):
context = {"greeting": "hello"}
return render(request, 'myapp/index.liquid', context)
If you’ve got multiple template engines configured, like in the example above, Django will use the first engine and template it finds matching the given template name. You can force Django to use a specific template engine with the using argument.
from django.shortcuts import render
def index(request):
context = {"greeting": "hello"}
return render(request, 'myapp/index.html', context, using='liquid')
Contributing
Install development dependencies with Pipenv
Python Liquid fully embraces type hints and static type checking. I like to use the Pylance extension for Visual Studio Code, which includes Pyright for static type checking.
Format code using black.
Write tests using unittest.TestCase.
Run tests with make test.
Check test coverage with make coverage and open htmlcov/index.html in your browser.
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
Hashes for django_liquid-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c82ecb8dba43ff6f1a0df36f2012636b30affd68a34fc46ebefcda67d24181dd |
|
MD5 | 7b64b8188e9a3f785767ada9e725307d |
|
BLAKE2b-256 | d7ea183b5319eaf1e97ba03346e127b2cbe52767d042c4c01fb391ac4541fdf9 |