Rileywiley
Rileywiley

Reputation: 139

Django Multiple models in one template

So I have a dashboard page in Django that I want to show info on more than just one model. I have figured out that I can add more info to the context object by overriding the get_context_data function. But know I don't know how to access the info in the template. Below is my view.py.

class StudyDashboard(generic.ListView):
    template_name = 'studies/studydashboad.html'
    context_object_name = 'study_list'
    queryset = Study.objects.all()

    def get_context_data(self, **kwargs):
        context = super(StudyDashboard, self).get_context_data(**kwargs)
        context['sites'] = StudySite.objects.all()
        return context

Here is by template tag that isn't working:

   <div class="box-body">
              {% for site in sites %}
                  <p>{% site.name %}</p>
              {% endfor %}
   </div>

This is the error I get:

TemplateSyntaxError at /studies/
Invalid block tag: 'site.name', expected 'empty' or 'endear'

Thank you in advance.

Upvotes: 0

Views: 829

Answers (1)

sww314
sww314

Reputation: 1332

You just have a syntax error in your template.

{% site.name %}

Should be:

{{ site.name }}

https://docs.djangoproject.com/en/1.9/topics/templates/#syntax

Upvotes: 1

Related Questions