django-tenant-schemas icon indicating copy to clipboard operation
django-tenant-schemas copied to clipboard

FilesystemLoader object has no attribute 'get_contents'

Open LorisLunedei opened this issue 6 years ago • 6 comments

Hi, I'm using Django 2.1.2 and I have problems with the 'Specializing templates based on tenants' feature. When I add the tenant_schemas.template_loaders.FilesystemLoader loader I receive this error: 'FilesystemLoader' object has no attribute 'get_contents'

It seems that in the newest django versions loader mechanism is changed a little (or I'm doing something wrong?).

That's my template configuration:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'OPTIONS': {
            'loaders': [
                'tenant_schemas.template_loaders.FilesystemLoader',
                'django.template.loaders.filesystem.Loader',
                'django.template.loaders.app_directories.Loader'
            ],
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

LorisLunedei avatar Oct 29 '18 08:10 LorisLunedei

I have made an attempt to fix this over at the django-tenants project: see https://github.com/tomturner/django-tenants/pull/198.

You might be able to re-use parts of that to create a pull request for this project as well.

jcass77 avatar Nov 02 '18 22:11 jcass77

Having the same issue wen trying to use 'per tenant templates'

gnalbandian avatar Dec 19 '18 16:12 gnalbandian

~Hi folks. Any news on this?~ I got it finally working on django2.2. One thing I'm still struggling with is - I think - wsgi configuration in local environment. Template dirs get updated only on server restart so on first request, given tenant's template rendered is the same for all tenants.

pmourelle avatar Nov 14 '19 12:11 pmourelle

Here's a PR with code brought from django-tenants that works fine and it's enough for us to keep working with dts: https://github.com/bernardopires/django-tenant-schemas/pull/608.

As a side question: porting to django-tenants seems the step to go as dts looks abandoned but had no time yet to check on needed changes. @goodtune @bernardopires thoughts on this? D-t-s should officially step aside in favor of d-t?

pmourelle avatar Nov 18 '19 12:11 pmourelle

No need to step aside, users already have freedom of choice.

goodtune avatar Nov 19 '19 08:11 goodtune

Sure thing. Cheers to that. That being said, if project is not on development nor maintenance any more, a note with link to <project currently active at the moment> in the readme would be much appreciated by people looking for a tenant solution.

pmourelle avatar Nov 19 '19 13:11 pmourelle