Accessing a model from middleware - django

Good practice / ability to access the model and do some processing in the intermediate process_request () method?

I am considering using middleware to analyze subdomains. These subdomains will represent cities, and I would like to know if there is a subdomain (or city) in our database.

Assuming I have a city model, can I import it and assemble 404 if the city does not exist?

+5
source share
1 answer

Is this a good practice? Of course. What it authdoes to add the user to the request.

Is it possible to import it? Of course. Can I collect 404 if the city does not exist? Of course.

Are you just looking for peace?

+6
source

All Articles