Как сделать шаблон с Python JSON в виде дерева? - PullRequest
0 голосов
/ 25 марта 2019

Мне нужно сделать HTML-шаблон с колбой.У меня есть dict в python, и я хочу показать его в виде дерева.Как я могу это сделать?

Я нашел этот ресурс: https://github.com/jonmiles/bootstrap-treeview, который может быть полезен, но я не могу его использовать.

dict_var = {
    "test3@test3.com": {
        "discord_id": 0,
        "status_key": False,
        "username": "test3@test3.com",
        "last_name": "aaaa",
        "gender": "male",
        "email": "test3@test3.com",
    },
    "test9@test9.com": {
        "username": "test9@test9.com",
        "last_name": "test9",
        "gender": "male",
        "discord_data": {
            "user": {
                "avatar": None,
                "discriminator": "111",
                "verified": True,
            },
            "connections": [],
            "guilds": [
                {
                    "icon": "hellohellohellohello.jpg",
                    "id": "222222222222",
                },
                {
                    "icon": None,
                    "id": "111111111",
                    "owner": True,
                }
            },
            "email": "hello@hello.com",
            "activation_key": "hello-hello-hello-hello-hello",
            "first_name": "hello@hello.com",
            "discord_id": 22222223333334444,
            "state": "IT"
        }
    }

Функция колбы для шаблона рендеринга

@app.route('/test')
def test():
   return render_template('test.html', res=dict_var)


test.html

...

<div class="container">
    <div id="tree"></div>

<script>
    $(function() {
  var mytree = JSON.parse('{{ res|safe }}');

  $('#tree').treeview({
    data: mytree
  });
});
</script>


...

как передать res в js и преобразовать dict в treeview?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...