0

Details: Client framwork: Django

Web server: Python + Flask

I have an HTML page which rendered with a data array. Each item in the array contains some fields. And one of the fields is a json object.

In order to improve the visibility of the json i've converted the json obj to html table.

Currently it's does't work. The results (on the browser) looks like that:

PasswordPolicy <table border="1"><tr><th>MinimumPasswordLength</th><td>16</td></tr><tr><th>RequireSymbols</th><td>True</td></tr><tr><th>Re

image1

Flask code:

@app.route("/PasswordPolicy", methods=["GET"])
@login_required
def get_password_policy():
    get_table_content = list(db_object.get_password_policy())
    search_event = request.args.get('searchquery')
    at_type = request.args.get('audittype')
        print("**************")
        for e in get_table_content:
            print("Before:")
            print(e['PasswordPolicy'])
            e['PasswordPolicy'] = json2html.convert(json = e['PasswordPolicy'])
            print("After:")
            print(e['PasswordPolicy'])

        print("get_table_content:")
        print(get_table_content[0])
        print("**************")
        return render_template(
            'soc2/password_policy.html',
            get_list=get_table_content
        )

Html content:

                        <table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
                        <thead>
                        <tr class="headings">
                            <th class="column-title">BusinessUnit </th>
                            <th class="column-title">ControllerNumber </th>
                            <th class="column-title">PasswordPolicy </th>
                        </tr>
                        </thead>

                        <tbody>
                        {% for elements in get_list %}
                        <tr class="even pointer">
                            <td>
                                {{ elements["BusinessUnit"] }}
                            </td>
                            <td>
                                {{ elements["ControllerNumber"] }}
                            </td>
                            <td>
                                {{ elements["PasswordPolicy"] }}
                            </td>
                        </tr>
                        {% endfor %}
                        </tbody>
                    </table>

The question is how to tell to the browser to parse the table as html instead of simple string

1

1 Answer 1

2

You can use safe like so: {{ your_html_string | safe }}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.