<table class="table table-striped">
<thead>
<tr>
<th>Net Balance</th>
<th>Post Date</th>
</thead>
</tr>
{%for a in results%}
<tr>
<td>{{a.0}}</td>
<td>{{a.1}}</td>
</tr>
{%endfor%}
</table>
<thead>
<tr>
<th>Net Balance</th>
<th>Post Date</th>
</thead>
</tr>
{%for a in results%}
<tr>
<td>{{a.0}}</td>
<td>{{a.1}}</td>
</tr>
{%endfor%}
</table>
`{{results|pprint}}` is pretty clear. You have a list of tuple. Tuples have no named member so a.nat_balance return a None value.
{{ a.0 }} in your django template is the equivalent of a[0] in python.
If you want dict-like object, your problem is with SQLalchemy, not django
2017-06-14 5:16 GMT+02:00 sum abiut <suabiut@gmail.com>:
Yes,on the database it spelt nat_balanceOn Wed, Jun 14, 2017 at 9:16 AM, Simon McConnell <simonmcconnell@gmail.com> wrote:<td>{{a.nat_balance}}</td>--
sure it shouldn't be spelt
<td>{{a.net_balance}}</td>
?
On Wednesday, 14 June 2017 06:57:30 UTC+10, suabiut wrote:Hi ludovic,Thanks for your response.when i did what you say it print out the date and sum in an array. Date still in Julian date but i don't worry about the date now just want to have the sum display nicely in my template
[(733011, 28397.54), (733030, 5136.79), (733044, 35.89), (733048, 0.0), (733049, 0.0), (733077, 6313.83), (733084, 6370.96), (733091, 150.0), (733104, -500.0), (733107, 0.0), (733108, 500.0), (733133, 5967.62), (733154, 7054.0), (733164, 0.0), (733174, 5698.18), (733195, 0.0), (733212, 5469.15), (733224, 0.0), (733255, 4887.2), (733265, -70000.0), (733286, 0.0), (733316, 0.0), (733342, -119.78999999999999), (733349, 0.0), (733377, 0.0), (733409, 0.0), (733422, -241.0), (733426, 241.0), (733440, 0.0), (733468, 0.0), (733498, 0.0), (733531, 0.0), (733559, 0.0), (733582, 104.59), (733589, 0.0), (733622, 0.0), (733651, 0.0), (733671, 3315.0), (733681, 0.0), (733713, 0.0), (733742, 0.0), (733772, -83.89), (733776, 0.0), (733777, 0.0), (733804, 0.0), (733832, 0.0), (733863, 0.0), (733895, 0.0), (733924, 0.0), (733948, 4.33), (733954, 0.0), (733986, 0.0), (734016, 0.0), (734046, 0.0), (734053, 0.0), (734077, 0.0), (734107, 0.0), (734137, -35.65), (734169, 0.0), (734197, 0.0), (734228, 0.0), (734260, 0.0), (734289, 0.0), (734319, 0.0), (734350, 0.0), (734381, 0.0), (734413, 0.0), (734442, 0.0), (734472, 0.0), (734501, -31.380000000000003), (734505, 0.0), (734534, 0.0), (734563, 0.0), (734595, 0.0), (734625, 0.0), (734655, 0.0), (734686, 0.0), (734716, 0.0), (734749, 0.0), (734777, 0.0), (734808, 0.0), (734840, 0.0), (734868, 0.0), (734900, 0.0), (734931, 0.0), (734960, 0.0), (734990, 3455.0), (735022, 1030.0), (735050, -2099.0), (735081, 460.0), (735113, -102.0), (735142, -980.0), (735173, 1538.9), (735204, 920.0), (735231, -500.0), (735233, 0.0), (735267, -1000.0), (735295, -1150.0), (735325, -250.0), (735355, 0.0), (735386, -560.69), (735415, 570.0), (735446, 0.0), (735477, -300.0), (735507, -205.70999999999998), (735540, 1600.0), (735569, -1040.0), (735598, -1404.31), (735614, 8.62), (735631, 0.0), (735649, 0.0), (735659, 0.0), (735689, 5.0), (735722, 0.0), (735750, 135.0), (735780, 770.0), (735813, 265.0), (735842, -1165.0), (735872, 30.0), (735904, -55.0), (735933, 4.29), (735967, 1105.0), (735968, 0.0), (735990, 4.32), (735995, 0.0), (736024, 0.0), (736055, 0.0), (736087, -1000.0), (736116, 0.0), (736146, 0.0), (736178, 0.0), (736208, 185.0), (736240, -285.68), (736269, 0.0), (736299, 0.0), (736332, 44.32), (736361, 0.0), (736389, 0.0), (736422, 0.0), (736451, -40.0), (736481, 0.0)] On Tue, Jun 13, 2017 at 5:33 PM, ludovic coues <cou...@gmail.com> wrote: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" <sua...@gmail.com> wrote:template.htmlview.pyHi,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
def SUMCORP(request):
engine=create_engine('mssql+pymssql://username:pass@serverna me /RBVData')
connection=engine.connect()
metadata=MetaData()
fund=Table('gltrxdet',metadata,autoload=True,autoload_with=e ngine)
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())
<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>
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.c--
You received this message because you are subscribed to the Google Groups "Django users" group.om .
To post to this group, send email to django...@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-y7tGoLm .2hxPaQpBrrm_j0VJvTF1UvE%3D-vQg bjh%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...@googlegroups.com .
To post to this group, send email to django...@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%2BTYqad .ry9dT8O2R0XQcivXae2OGWYaA%2Boe fTmO4wL22DCQ%40mail.gmail.com
For more options, visit https://groups.google.com/d/optou
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/81c3ba9f-c47d .-4e85-8987-0c306f26b467%40goog legroups.com To view this discussion on the web visit https://groups.google.com/d/--
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 .msgid/django-users/CAPCf- y7cvSm0YrGh24Fiz_ N4xuCHijDxpP0r3P% 3Db37XqHCuQYQ%40mail.gmail.com .
Cordialement, Ludovic Coues
+33 6 14 87 43 42
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%2BTYbimh5EKdsS9%3DDX291hLkz-hcZ27SF%3DHQstm3Uc8e1YA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment