Can I Use Django's context processor in Django rest framework

Viewed 20

I have a question

I need to store some data globally so I can access them anywhere in my Djangorestframework application, kind of like how flask provides flask.g for this. Can I use Django context processor for this? I know I can use Django context processor if I am working with Django templates, I just want to know if it is possible for me to use it with Djangorestframework

1 Answers

Yes you can. Every context processor is a function.

for example:

# everywhere in your code:
from django.template.context_processors import i18n
result_of_i18n = i18n(None)  # answer is dictionary with i18n settings.
Related