【问题标题】:How to put object in hidden input field using html and cheeypy如何使用 html 和 cheeypy 将对象放在隐藏的输入字段中
【发布时间】:2019-11-28 09:33:36
【问题描述】:
    below is abc.html

    <div xmlns:xi="http://www.w3.org/2001/XInclude"
         xmlns:py="http://genshi.edgewall.org/" py:strip="True" >
            <div class="insync-bluthm-tbl-wrp">
                <div class="insync-bluthm-tbl-scroll">
                    <div class="insync-bluthm-tbl-scroll-inr">
                        <table class="insync-bluthm-tbl">
                        <thead>
                            <tr>
                                <th><div>File Name</div></th>
                            </tr>
                        </thead>
                        <tbody>
                            <input type="hidden" id="restorable_data" value="${restoreData}"/>
                            <tr>
                                <td><div>Dummy File name</div></td>
                            </tr>
                        </tbody>
                    </table>
                    </div>
                </div>
            </div>
    </div>

    below is python function

    @cherrypy.expose
    def can_restore_mds(self, *args, **kwargs):
    restoreData = {
            'abc': 'def',
            'akjshd': 'asd',
            'is_valid': 1,
    }
    restore_context = {
        'page': 'abc.html',
        'restoreData': restoreData,
    }
    html = render_page(restore_context, restore_context['page'])
    return {
        'html': html,
        'restoreData': restoreData,
    }
    return response

“restoreData”是变量,在服务器端渲染中没有以正确的格式注入,任何人都可以帮忙做些什么吗?

【问题讨论】:

    标签: python html cherrypy


    【解决方案1】:

    您可以使用 json dumps 函数来执行此操作:-

    Python

    # remember to import json in your python file
    restoreData = {
        'abc': 'def',
        'akjshd': 'asd',
        'is_valid': 1,
    }
    restore_context = {
        'page': 'abc.html',
        'restoreData': json.dumps(restoreData),
    }
    

    HTML

    <input type="hidden" id="restorable_data" value="${restoreData}"/>
    

    【讨论】:

      猜你喜欢
      • 2011-09-28
      • 2016-06-29
      • 1970-01-01
      • 1970-01-01
      • 2023-04-08
      • 2020-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多