[Fixed]-How to create an object in one file and use everywhere in Django?

1đź‘Ť

You could do this, although I don’t think it’s good style. Even though you have complete control over the names in includes.py, you are still cluttering up your namespace for the sake of saving a bit of typing, and sooner or later it will bite you. Also, “Explicit is better than implicit”.

includes.py:

from json import  loads, dumps
# and anything else you want widely defined

test.py: and any other files where you want to use loads or dumps

from includes import *
print dumps([{},{}] )  # which works
👤nigel222

Leave a comment