Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

accessing model from middleware - django

Tags:

django

Is it good practice/possible to access a model, and do some processing in a middleware's process_request() method?

I am thinking of using middleware to parse out subdomains. These subdomains will represent cities, and I would like to know if the subdomain (or city) exists in our database.

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

like image 379
AlexBrand Avatar asked May 11 '12 14:05

AlexBrand


1 Answers

Is it good practice? Sure. That's what auth does to add the user to the request.

Can I import it? Sure. Can I raise a 404 if the city doesn't exist? Sure.

Are you just looking for placation?

like image 131
Chris Pratt Avatar answered Oct 16 '22 03:10

Chris Pratt