Skip to content

Instantly share code, notes, and snippets.

Last active August 29, 2015 14:17
Show Gist options
  • Save JamesHovious/459fdb492944a730fe5b to your computer and use it in GitHub Desktop.
Save JamesHovious/459fdb492944a730fe5b to your computer and use it in GitHub Desktop.
<table class="table table-striped table-bordered">
<th>First Name</th>
<th>Last Name</th>
<td id="first_name"></td>
<td id="last_name"></td>
<td id="date"></td>
<script src="{{ STATIC_URL }}js/brython/brython.js" type="text/javascript"></script>
<body onload="brython()">
<script type="text/python">
from browser import document, ajax
#Ajax arguments
getqs = """json={"tag":"account_page","data":{"first_name": "John","last_name": "Doe","email":"","password":"P@$$w0rd","date":"March 15 2015"}}"""
postqs = qs = """json={"tag":"account_page","data":{"email":"","first_name": "firstname","last_name": "lastname","account_type":"individual",}}"""
url = 'http://[your-domain-name].com/[your-view-name]'
def post_data(url, qs):
req = ajax.ajax()
# Bind the complete State to the on_post_complete function
# send a POST request to the url'POST',url,True)
# send data as a dictionary
def get_data(url, qs):
req = ajax.ajax()
# Bind the complete State to the on_get_complete function'GET', url+'?'+qs, True)
req.set_header('content-type', 'application/x-www-form-urlencoded')
def on_post_complete(req):
if req.status==200 or req.status==0:
# Take our response and inject it into the html div with id='main'
document["main"].html = req.text
document["main"].html = "error "+req.text
def on_get_complete(req):
if req.status==200 or req.status==0:
document["get"].html = "error "+req.text
def populate_table(data):
data_list = data['results']
last = data_list.pop(2)
first = data_list.pop(1)
date = data_list.pop(0)
document['first_name'] <= first
document['last_name'] <= last
document['date'] <= date
get_data(url, qs)
post_data(url, qs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment