Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not work with Jinja2 out of the box #82

Open
IlyaSemenov opened this issue Aug 11, 2016 · 1 comment
Open

Does not work with Jinja2 out of the box #82

IlyaSemenov opened this issue Aug 11, 2016 · 1 comment

Comments

@IlyaSemenov
Copy link
Contributor

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

  1. Add 'webassets' and 'django_assets' to INSTALLED_APPS
  2. Add 'django_jinja.backend.Jinja2' (or 'django.template.backends.jinja2') to TEMPLATES
  3. Add 'webassets.ext.jinja2.AssetsExtension' to Jinja2 extensions
  4. 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.

@fpuga
Copy link

fpuga commented Aug 28, 2018

I also fall into this. Thanks a lot for the workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants