Where to set Python environment attributes for a Django project?

For example, the Python class decimal.Decimal() has a context. You can view the current context with getcontext() and set new values ​​for precision, rounding, or enabling traps.

If you want to set a new value for the context so that it is visible throughout the Django project, where would it be best to do this?

eg. Throughout the project, the FloatOperation signal must be captured.

 from decimal import FloatOperation, getcontext context = getcontext() context.traps[FloatOperation] = True 

Also use getcontext() to return the current context for the active thread. Besides explicitly creating new threads in the project, is there any additional consideration for Django to create additional threads.

+5
source share
1 answer

I would suggest a core or common application that includes your installation as part of AppConfig.ready() .

https://docs.djangoproject.com/en/1.7/ref/applications/#django.apps.AppConfig.ready

+2
source

Source: https://habr.com/ru/post/1235774/


All Articles