Themes and local proxies in Werkzeug. Application

First, I want to make sure that I understand the purpose of the function correctly. A local proxy function assigned to share variables (objects) through modules (packets) in a stream. I'm right?

Secondly, the use is still unclear to me, maybe because I misunderstood the assignment. I am using Flask. If I have two (or more) modules: A, B. I want to import an object C from module A to module B. But I cannot do it the usual way, from A import C , because this will cause cyclic import and after that ImportError. How to solve this problem using a local Werkzeug proxy? And should I do this with Werkzeug?

module A:

 from werkzeug.local import LocalSomething # LocalProxy or LocalStack C = 'C' # Somehow add C to LocalSomething 

module B:

 from werkzeug.locla import LocalSomething C = LocalSomething()['C'] 
+7
source share
1 answer

Module Z:

 from werkzeug.local import Local myLocals = Local() 

module A:

 from Z import myLocals myLocals.C = "C" 

module B:

 from Z import myLocals C = getattr(myLocals, "C", None) 

Is this what you are looking for?

+6
source

All Articles