Calling JavaScript function from Python with js2py causes ReferenceError: document is not defined

Calling JavaScript function from Python with js2py causes ReferenceError: document is not defined

我正在尝试从 python 调用 javascript 函数来更改 DOM,但我无法做到。只需控制台记录一条消息即可,但一旦我尝试影响 DOM,我就会收到标题中提到的错误。我确定这里缺少一些基本的东西...有什么建议或解决方法吗?

app.py

app = Flask(__name__)

@app.route('/')
def index():
    return render_template("index.html")

@app.route('/python_func')
def python_func():
    eval_res, jsFile = js2py.run_file('static/test.js')
    jsFile.hello()
    return "nothing"

test.js

function hello() {
    console.log("hello") <--- Works
    let div = document.createElement("div") <--- This doesn't
}

script.js(这个按钮调用python函数)

$(function() {
    $('#startbtn').bind('click', function() {
        $.getJSON('/python_func',
            function(data) {
        //do nothing
        });
        return false;
    });
});

我发现 Js2Py 无法 运行 具有 DOM 依赖项的 JS 代码。