On 16/06/2017 12:12 PM, sum abiut wrote:
Is it possible to pass data from two different django functions to a one template in a single for loop?

Yes. The general way to do that (and pretty much all Django things) is to write a "view" which can contain as many functions as desired and fetch as much data from the database as desired.

The view software then creates one or more named object(s) or perhaps assembles a dictionary or a list of tuples or a tuple of tuples and renders that data via a named template.

  ... here go all your functions to create myObject and myOtherThing ...
  ... They can both be passed to the template as follows ...

  return render(
        request=request,
        template_name='mytemplate.html',
        context={
            'thing'=myObject,
            'otherthing'=myOtherThing,
        }
  )

The template expects the named object or objects or dictionaries etc and displays the data via template variables for example

{% if otherthing %}
  <p>Other thing exists: {{ otherthing.percentage }} </p>
{% endif %}
{% if thing.thing_list %}
  {% for item in thing.thing_list %}
    {{ item.name }} {{ item.size }} {{ item.modified_date }}
  {% endfor %}
{% endif %}

hth


Cheers,
--
You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com <mailto:django-users+unsubscr...@googlegroups.com>. To post to this group, send email to django-users@googlegroups.com <mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPCf-y4nSH-WQUcR4sCzy6OSg9q_dVTpEbf2%2BrDmUF-fmgRrJA%40mail.gmail.com <https://groups.google.com/d/msgid/django-users/CAPCf-y4nSH-WQUcR4sCzy6OSg9q_dVTpEbf2%2BrDmUF-fmgRrJA%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/66ecd8a2-b23d-aae1-ab22-eaebebbc9ffb%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

Reply via email to