How to redirect on another page and pass parameter in url from table?

Set the user name as data-username attribute to the button and also a class: HTML <input type=”button” name=”theButton” value=”Detail” class=”btn” data-username=”{{result[‘username’]}}” /> JS $(document).on(‘click’, ‘.btn’, function() { var name = $(this).data(‘username’); if (name != undefined && name != null) { window.location = ‘/player_detail?username=” + name; } });​ EDIT: Also, you can simply check for undefined … Read more

How to run Flask app with Tornado

The Flask docs used to describe how to do this, but it has been removed due to the performance notes below. You don’t need Tornado to serve your Flask app, unless all your async code is already written in Tornado. The Tornado docs about WSGI describe this as well. They also include a big warning … Read more

Is JSON Hijacking still an issue in modern browsers?

No, it is no longer possible to capture values passed to the [] or {} constructors in Firefox 21, Chrome 27, or IE 10. Here’s a little test page, based on the main attacks described in http://www.thespanner.co.uk/2011/05/30/json-hijacking/: (http://jsfiddle.net/ph3Uv/2/) var capture = function() { var ta = document.querySelector(‘textarea’) ta.innerHTML = ”; ta.appendChild(document.createTextNode(“Captured: “+JSON.stringify(arguments))); return arguments; } … Read more

How can I periodically execute a function with asyncio?

For Python versions below 3.5: import asyncio @asyncio.coroutine def periodic(): while True: print(‘periodic’) yield from asyncio.sleep(1) def stop(): task.cancel() loop = asyncio.get_event_loop() loop.call_later(5, stop) task = loop.create_task(periodic()) try: loop.run_until_complete(task) except asyncio.CancelledError: pass For Python 3.5 and above: import asyncio async def periodic(): while True: print(‘periodic’) await asyncio.sleep(1) def stop(): task.cancel() loop = asyncio.get_event_loop() loop.call_later(5, stop) … Read more

how to show non ASCII character using python [closed]

gs.translate(‘this is a pen’,’bn’) produces a Unicode string. If you just type gs.translate(‘this is a pen’,’bn’) into the interactive interpreter it prints the representation of that string which is u’\u098f\u0987 \u098f\u0995\u099f\u09bf \u0995\u09b2\u09ae’. But when you type print(gs.translate(‘this is a pen’,’bn’)) the Unicode data is encoded into a stream of bytes using the default encoding (which … Read more