python - How to load an object into memory for entire django project to see? -
i'd assume loaded settings.py, , object imported settings, wanted know if there more standard or recommended way this. people load items entire project needs see?
ex.
# settings.py ... something_large = json.loads(...) # whatever models.py, views.py, etc project.settings import something_large #is proper way it?
thanks.
you load in, say, data
module in app make cleaner.
(i'm showing how load file same directory module in.)
project/ settings.py ... myapp/ __init__.py data.py huge_static_data.json models.py ...
myapp/data.py
:
with file(os.path.join(os.dirname(__file__), "huge_static_data.json")) in_f: something_large = json.load(in_f)
myapp/models.py
:
from myapp.data import something_large
python's import system ensures data loaded once, when module first imported.
Comments
Post a Comment