Django middleware using Django models?
-
13-12-2019 - |
Question
Is it possible to use regular Django models from within Middleware?
I have been looking for simple examples but couldn't find anything about the availability of such parts of the Django framework to middleware. I believe from my limited understanding that they should be.
Solution
The model system is available from everywhere in your django application, as long as you import the relevant models. It is not tied to the HTTP lifecycle.
OTHER TIPS
Yes, i agree with @marcin you can use models anywhere, and as a reference you can look at django flatpages middleware, there it took the decision which flatpage
should be rendered.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow