niwinz / django-jinja

Simple and nonobstructive jinja2 integration with Django.
http://niwinz.github.io/django-jinja/latest/
BSD 3-Clause "New" or "Revised" License
363 stars 102 forks source link

'Environment' object has no attribute 'install_gettext_translations' #187

Closed SG5 closed 7 years ago

SG5 commented 7 years ago

in file "/usr/local/lib/python3.5/site-packages/django_jinja/backend.py", line 193 my settings:


    {
        'BACKEND': 'django_jinja.backend.Jinja2',
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
            ],
            'extensions': [
            ],
            "match_extension": ".html",
        },
    },
    {
        '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',
            ],
        },
    },
]```
niwinz commented 7 years ago

Can you provide a test case for that. I'm asking for that because this just works on my applications.

SG5 commented 7 years ago
  1. Install django and django-jinja with pip
  2. Init basic project with django-admin startproject mysite.
  3. Change dir to mysite and create simple view and route for it
    
    #views.py
    from django.shortcuts import render

def test(request): return render(request, 'main/test.html')

```python
#urls.py
from django.conf.urls import url
from django.contrib import admin

from .views import test

urlpatterns = [
    url(r'^$', test),
    url(r'^admin/', admin.site.urls),
]
  1. In settings.py replace TEMPLATES variable to config from first message
  2. Apply migrations with python manage.py migrate and run server python manage.py runserver
  3. Open http://127.0.0.1:8000/ in browser and watch error message
niwinz commented 7 years ago

In your configuration, you are explicitly disables all extensions with extensions: [], however, in your settings you have the i18n activated. In jinja i18n is managed by a extension and if you explicitly overwrites it with an empty list, you shouldn't expect that this will going to work as expected.

x-yuri commented 5 years ago

@niwinz I've run into this as well. I think the documentation is not really clear.

Auto-load templatetags compatible with Jinja2 the same way as Django.

I'm not sure what this means, load tag doesn't work.

Django template filters and tags can mostly be used in Jinja2 templates.

Which ones? load tag doesn't work. Okay, I deleted those. Then now tag. So I started looking into the code. I saw that there are builtin filters, and extensions. Why enabling each and every filter if I can just enable a couple of extensions? So I added:

'extensions': [ 'django_jinja.builtins.extensions.DjangoFiltersExtension' ],

And got the error above. Now I see that django-jinja by default enables a number of extensions. And yes, I've failed to notice the DEFAULT_EXTENSIONS + part. But if the documenation were to mention which filters and tags are available by default, even if by pointing out at a file to look into, some of the users would probably save some time finding their way with the library.

And I'm still not sure if any Django tags work.