Answer the question
In order to leave comments, you need to log in
How to use the same variable instance in different Django applications?
Hello.
I have a large variable that I load once to speed up the processing of user requests. Here is the project/app1/apps.py file
from django.apps import AppConfig
class Config(AppConfig):
data = load_data()
from django.apps import apps
settings = apps.get_app_config('app1')
# Здесь данные, которые я присвоил переменной в apps.py
data = settings.data
Answer the question
In order to leave comments, you need to log in
According to the description - the problem should be solved completely differently than described in the question.
Evgeny_A django already has a similar mechanism in the sites app. You should do something like this:
# file_1.py
BIG_VAR = []
class BigVarClass:
@staticmethod
def get_big_var(self):
return BIG_VAR
@staticmethod
def set_big_var(self, big_var):
global BIG_VAR
BIG_VAR = big_var
# file_2.py
from .file_1 import BigVarClass
BIG_VAR = BigVarClass.get_big_var()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question