django-settings-export
django-settings-export copied to clipboard
settings are not injected when using render_to_string
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.1Django==3.2.4