Answer the question
In order to leave comments, you need to log in
Django: How to inject data from the database into each page (a la @inject in Laravel)?
Hello everyone, on each page in the footer there is a block with contacts. The contacts themselves are stored in the database. The first thing that comes to mind: in each view in the context, add a selection from the database by the contacts key, but if the number of views grows, then all this will become unmanageable. The second thought is to write your own context processor returning a dictionary consisting of a selection from the database, after which append it to the main context formed in the View and feed it to the template. There are also several questions here, is it correct to access the database from the context processor and then join them with the context formed in the View? Maybe there is a solution that floats somewhere in the documentation, where I have not rummaged through yet?
ps: for example, in the php laravel framework there is an @inject function built into the blade that allows you to access the ORM entity directly from the template.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question