Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create application scope variable django?

Tags:

django

How can I create an application scope variable which is loaded when the django app starts, be in memory and accessible by all.

Basically I want to reuse the variable through out the application without reloading it.

Thanks

like image 254
Vishal Avatar asked Nov 23 '09 06:11

Vishal


2 Answers

You could add it to your settings.py file. Or, add it to the __init__.py file inside the app directory.

like image 181
Edward Dale Avatar answered Oct 28 '22 11:10

Edward Dale


Are you referring to something like an environment variable? You could load it via init...

__init__.py

import os
os.environ['APP_VAR_WHATEVER'] = 'hello world!'
like image 42
T. Stone Avatar answered Oct 28 '22 11:10

T. Stone