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.

Was it helpful?

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
scroll top