-1

From what it seems like, after calling a Jinja function, the return value is "set in stone" and cannot be changed, however, I need a way to call a Jinja function and get its current return value continuously. Currently I have the following code:

app.py [SNIPPET]

def statusupdate():
    return status

app.jinja_env.globals.update(statusupdate=statusupdate)

index.html [SNIPPET]

<script>
function stat(){
    if ("{{ statusupdate() }}" == "Done"){
        clearInterval(id)
        window.location.href = '/results'
    } else {
        document.getElementById("status").innerHTML = "{{ statusupdate() }}"
    }
}
id = setInterval(stat, 0)
</script>

Throughout app.py, the status variable is changing quite a bit. However, the page and specifically the element with id "status" is frozen at the initial value and is never updated. Is there a way to allow this to update?

An0n1m1ty
  • 448
  • 4
  • 17

1 Answers1

-1

I use something like this:

def func_to_fetch_from_db(variable):
    ...

@app.context_processor
    def inject_global_vars():

        base_context = {
            'status': func_to_fetch_from_db('status'),
        }

        return base_context

Putting in db is best for me. The demo can be seen in use in the shopyo app.