[Answer]-How to put multiple models on the same page?

1👍

Try using an inclusion tag. You can create a function for doing all of the work to create the sessions and then associate that with a particular block of HTML.

templatetags/session.py

@register.inclusion_tag('includes/session_box.html')
def output_session_box(...):
    ...
    return { .. }

The associated template file, includes/session_box.html, would have the HTML like any template.

And then your base.html would have:

{% load session %}
{%  output_session_box ... %}
👤TAH

0👍

Use RequestContext and a context_processor to inject template variables into every view using RequestContext.

It’s as simple as a python function accepting request as an arg, and returning a dictionary to be passed into your template.

https://docs.djangoproject.com/en/dev/ref/templates/api/#django.template.RequestContext

def my_processor(request):
    return {'foo': 'bar'}

TEMPLATE_CONTEXT_PROCESSORS = (
     # add path to your context processor here.
)

I generally have a per-project processor for the basics… It’s exactly how django adds {{ user }} or {{ STATIC_URL }} to every template.

Leave a comment