2

I have a flask backend sending data to the client. Some JS on the client side then utilizes that data to construct a page that includes one row of data and another area below the row that has a d3 display with clickable nodes.

The nodes have different properties corresponding to different models in the backend and different html templates. Given a type, when clicked, a different html template is presented in the row above.

How do I set the template from the JS? I tried doing something like:

$("#div_id").innerHTML = "{% set obj = " + obj + "%}{% include '" + obj_template_file + "' %}"

That (perhaps of course) didn't work. After taking care of escaping, it just displays that string. I thought of dirty ways of doing this like using hide and show liberally but that doesn't seem wise.

4

1 に答える 1

1

「クライアントにデータを送信する」という意味が明確ではありませんが。次のように、ルートから base_template 引数を渡すことができます。

@auth.route('/<path:path>', methods=['GET', 'POST'])
def password_reset_request():
    if path ==2:
         base_template = "jay.html"
    if path ==3:
         base_template = "blue.html"
    ...
    return render_template('auth/reset_password.html', base_template=base_template)

そしてテンプレートで:

{% extends base_template %}

次に、JavaScript フロントエンドから URL を取得するだけです。

于 2015-09-17T15:55:52.027 に答える