Python AJAX Server
Pyxer is a Python AJAX Server/ Framework similar to the Jaxer project of Aptana.
- Discussion:
Please join the discussion about this project here
http://groups.google.de/group/pyxer - Download:
You will find new releases in the Cheese Shop
http://pypi.python.org/pypi/Pyxer
Short introduction
Instead of writing client side code in Javascript you can use Python. The Python code will be translated to Javascript before send to the client. You may also have server side code defined in the HTML file that can asynchronously be called form the client with seamless use of AJAX in the background.
I think an example tells more than thousand words:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Proxy Demo</title>
</head>
<body>
<form action="" onSubmit="save_data(document.getElementById('num').value); return false;">
Value between 5 an 50
<input type="text" value="" id="num" onChange="validate(this.value)">
</form>
<script language="Python" type="text/python" runat="both">
def validate(value):
value = int(value)
if not (5 <= value <= 50):
alert("Number not in range!")
return False
return True
</script>
<script language="Python" type="text/python" runat="server-proxy">
def save_data(value):
file("counter.txt", "w").write(value)
def load_data():
return file("counter.txt", "r").read()
</script>
<script language="Python" type="text/python" runat="client">
def onload():
document.getElementById('num').value = load_data()
window.onload = onload
</script>
</body>
</html>
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Proxy Demo</title>
</head>
<body>
<form action="" onSubmit="save_data(document.getElementById('num').value); return false;">
Value between 5 an 50
<input type="text" value="" id="num" onChange="validate(this.value)">
</form>
<script language="Python" type="text/python" runat="both">
def validate(value):
value = int(value)
if not (5 <= value <= 50):
alert("Number not in range!")
return False
return True
</script>
<script language="Python" type="text/python" runat="server-proxy">
def save_data(value):
file("counter.txt", "w").write(value)
def load_data():
return file("counter.txt", "r").read()
</script>
<script language="Python" type="text/python" runat="client">
def onload():
document.getElementById('num').value = load_data()
window.onload = onload
</script>
</body>
</html>
