我创建了一个Python动力Web框架旨在尽可能使用JavaScript尽可能小。需要做一些像uilang这样的轻量级事件来将事件传递给我的Python代码。我想这应该是jQuery解决方案以某种方式pinging观察者对象(?)。Python后端与JS前端
我发现了一些努力来创建纯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。
您需要在展开这样一个史诗般的创作之前,对客户端和服务器技术如何协同工作做更多的研究。可以从以下开始:https://pythonprogramming.net/jquery-flask-tutorial/ –