Han Chuang
unread,Mar 19, 2013, 6:04:32 PM3/19/13Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mako-d...@googlegroups.com
Hello,
I'm starting out with Mako, I've been working on a project that makes query to a local sqlite db and passes the results into a mako template to be drawn with javascript (Extjs)
def myView(request):
response = request.db.execute("select * from myTable);
results = [dict(name=row[0], id=row[1], start=row[2], end=row[3]) for row in response.fetchall()]
return dict(results=results)
The results are passed into a template and handled, being passed into a javascript function to draw the results.
% if results
<h2>RESULTS FOUND</h2>
% for result in results:
<script>
myFunction(${result['name']}, ${result['id']}, ${result['start']}, ${result['end']});
</script>
% endfor
% else
<h2>RESULTS LOST</h2>
% endif
However, the dbs I will be using have unexpected {null} items (in this case, end can be null, as can start.) Passing a none to a javascript method seems to break it and not execute it at all. How can I handle nulls in mako?
One method I've found so far is to create an if else statement for each field that can be null, then doing
% if result['name']:
<Do the method that has it>
% else
<Do a separate method that doesn't have it>
% endif
But this results in a lot of duplicated code and seems to be inefficient.
Summary: How can I change a None in mako to a null for javascript?
Thank you in advance!