【发布时间】:2017-05-12 18:26:47
【问题描述】:
我正在创建一个基于 Python 的 Web 框架,旨在尽可能少地使用 javascript。需要制作像 uilang 这样的轻量级东西来将事件传递给我的 Python 代码。我想这应该是 jQuery 解决方案以某种方式 ping 某种观察者对象(?)。
我发现了一些创建纯 Python 接口(如 Remi)的努力,但仍然不知道应该如何在我的代码中重新实现它。
假设我做了一个这样的课程:
class WebView():
def __init__(self, template, **callbacks):
"""
Callbacks are dict, {'object': callback}
"""
self.template = template
self.customJS = None
for obj, call in callbacks:
self.setCallback(obj, call)
def __call__():
"""
Here I return template
Assume {{customJS}} record in template, to be simple
"""
return bottle.template(self.template, customJS = self.customJS)
def setCallback(self, obj, call):
"""
Build custom js to insert
"""
self.customJS += ('<script ....%s ... %s' % (obj, call))
那么,我怎样才能让 JS 将事件从按下按钮传回我的回调?
我知道这个问题可能过于宽泛,但我只是想尽可能地描述一下,因为我真的一点也不了解 JS。
【问题讨论】:
-
您需要对客户端和服务器技术如何协同工作进行更多研究,然后再着手进行如此宏大的尝试。可能开始于:pythonprogramming.net/jquery-flask-tutorial
标签: javascript jquery python bottle