django-settings-export icon indicating copy to clipboard operation
django-settings-export copied to clipboard

settings are not injected when using render_to_string

Open kennell opened this issue 3 years ago • 0 comments
trafficstars

Hi,

It seems the package does not inject settings variable when directly calling render_to_string.

Example:

settings.py

TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates',
            'DIRS': [
                os.path.join(BASE_DIR, 'templates')
            ],
            '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',
                    'django_settings_export.settings_export'
                ],
            },
        },
    ]
FOO = 'FOO'
SETTINGS_EXPORT = [
        'FOO'
]

template.txt

{{ settings.FOO }}

some_file.py (executed from Django-context)

from django.template.loader import render_to_string
s = render_to_string('template.txt')

Result: rendered string s is empty instead of containing the value of settings.FOO.

Versions used:

  • Python 3.9.13
  • django-settings-export==1.2.1
  • Django==3.2.4

kennell avatar Nov 21 '22 00:11 kennell