Monday, June 26, 2017

Re:

On 27/06/2017 10:00 AM, sum abiut wrote:
> Hi all,
> I have this function where i i use mssqlalchmy to to fetch data from a
> mssql database. I am fetching data from a column but what i am
> interested in, is just to get a data from last field/row on that column.
>
> is there are way to get that done from template?. this what i have
> done from the template.html but i am getting an error : could not
> parse the remainder '[-1]'
>
>
>
> template.html
>
> <table class="table table-striped">
> <thead>
> <tr>
>
> <th> GL Rate</th>
>
> </thead>
>
> </tr>
> {%for a in results%}
>
> <tr>
>
> <td>{{a.buy_rate[-1]}}</td>


<td>{{ a.buy_rate | last }}</td>

https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#last


>
> </tr>
>
> {%endfor%}
> </table>
>
>
> view.py
> def rate(request):
> engine=create_engine('mssql+pymssql://username:passwprd@localhost
> /database')
> connection=engine.connect()
> metadata=MetaData()
> funds=Table('mccurtdt',metadata,autoload=True,autoload_with=engine)
>
> stmt=select([funds.columns.buy_rate])
> stmt=stmt.where(and_(funds.columns.rate_type=='MID',funds.columns.from_currency=='AUD',))
> results=connection.execute(stmt).fetchall()
> return render_to_response('rate.html',locals())
>
> --
> 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
> <mailto:django-users+unsubscribe@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-y5EMP6qx59zzfQ-xx-7kz2QbUO%2Bq23pPvJdXTb0B9fdqw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAPCf-y5EMP6qx59zzfQ-xx-7kz2QbUO%2Bq23pPvJdXTb0B9fdqw%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+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/b8e6ef53-f6d3-0feb-b5ef-015f983d7e2f%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment