The current documentation misleads that django-assets will work with Django and Jinja2. It will not, not out of the box at least.
Steps to reproduce
Add 'webassets' and 'django_assets' to INSTALLED_APPS
Add 'django_jinja.backend.Jinja2' (or 'django.template.backends.jinja2') to TEMPLATES
Add 'webassets.ext.jinja2.AssetsExtension' to Jinja2 extensions
Add {% assets "js/main.js", output="min/main.js" %}{% endassets %} to your template file
What happens
File "/Users/semenov/test/var/venv/lib/python3.5/site-packages/webassets/ext/jinja2.py" in _render_assets
Exception Type: RuntimeError at /test/
Exception Value: No assets environment configured in Jinja2 environment
Expected
The environment should be automatically configured; or it should be clearly documented how to configure it manually.
Current workaround
Create a custom extension:
# myapp/jinja2_assets.py
from jinja2.ext import Extension
from django_assets.env import get_env
class AssetsExtension(Extension):
def __init__(self, environment):
super().__init__(environment)
environment.assets_environment = get_env()
then add myapp.jinja2_assets.AssetsExtension to the list of Jinja2 extensions.
Problem
The current documentation misleads that django-assets will work with Django and Jinja2. It will not, not out of the box at least.
Steps to reproduce
'webassets'
and'django_assets'
toINSTALLED_APPS
'django_jinja.backend.Jinja2'
(or'django.template.backends.jinja2'
) toTEMPLATES
'webassets.ext.jinja2.AssetsExtension'
to Jinja2 extensions{% assets "js/main.js", output="min/main.js" %}{% endassets %}
to your template fileWhat happens
Expected
The environment should be automatically configured; or it should be clearly documented how to configure it manually.
Current workaround
Create a custom extension:
then add
myapp.jinja2_assets.AssetsExtension
to the list of Jinja2 extensions.