Is it possible to create a view for a template module?

I have a set of modules that get included in all of my main templates in all of my apps, but these modules require database access, which works fine in the home app but to make it work in the other apps I would have to copy/paste the view from home to the other apps. idk if this is making sense so I’ll show my code:

            {% include "home/mobile_nav.html" %}
            {% include "home/desktop_nav.html" %}
            {% include "home/hero.html" %}

            <div id='call_to_action'>
                <h3>Ready to Shape the Future?</h3>
                <p>Click Here</p>
            <div id='recent'>
                <h2>Recent Work</h2>
                {% if latest_projects_list %}
                    {% for project in latest_projects_list %}
                    <a href="#placeholder"><img src="" alt=""></a><!--placeholder src-->
                    {% endfor %}
                {% else %}
                    <p id="recent_else">No projects available.</p>
                {% endif %}


        {% include "home/footer.html" %}

the footer and navs pull data from the projects and posts models. because the index view contains those data pulls, it works fine there, but I would have to copy those data pulls to all the other views to make them work there. Is there a way I can, for example, make a view specifically for footer.html?

What you may be looking for here is a custom context processor.
(Also see the example at Writing your own context processors).

It’s the mechanism by which you can inject data into every context before it’s rendered.

We use one to add a context-sensitive menu on every page.

1 Like

you’re always so helpful and knowledgeable :smiley: