Monday, June 12, 2017

Re: passing data to template

Try `{{ results | pprint }}` in your template.

That will not solve your problems but that will give you a lot more information about what data have been passed to your template.

On 13 Jun 2017 6:53 am, "sum abiut" <suabiut@gmail.com> wrote:
Hi,
I need some help, i am using Django as my web framework and sqlalchemy to query my database. When i pass data template its not showing on the template. can someone point me to the right direction.

The post date is loaded on the template but the Net Balance is not loaded. Don't know what i am doing wrong here.

below is my view.py and template


view.py

def SUMCORP(request):
    engine=create_engine('mssql+pymssql://username:pass@servername /RBVData')
    connection=engine.connect()
    metadata=MetaData()
    fund=Table('gltrxdet',metadata,autoload=True,autoload_with=engine)
    stmt=select([fund.columns.date_posted,func.sum(fund.columns.nat_balance)])
    stmt = stmt.where(fund.columns.account_code=='002CORP')
    stmt=stmt.group_by(fund.columns.date_posted)
    results=connection.execute(stmt).fetchall()
    return render_to_response('fundmanager_sum.html',locals())


template.html

<table class="table table-striped">
  <thead>
<tr>
 
  <th>Net Balance</th>
  <th>Post Date</th>
</thead>

</tr>
{%for a in results%}

<tr>

<td>{{a.nat_balance}}</td>
    <td>{{a.date_posted}}</td>

  </tr>

{%endfor%}
</table>

--
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+unsubscribe@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/CAPCf-y7tGoLm2hxPaQpBrrm_j0VJvTF1UvE%3D-vQgbjh%3DzCxEMg%40mail.gmail.com.
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+unsubscribe@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/CAEuG%2BTYqadry9dT8O2R0XQcivXae2OGWYaA%2BoefTmO4wL22DCQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment