【问题标题】:How to convert array from MongoDB to String in HTML?如何将数组从 MongoDB 转换为 HTML 中的字符串?
【发布时间】:2021-03-29 05:11:19
【问题描述】:

在我的每个收藏条目中,它们都有一组作者(字符串格式)。我想在我的页面 HTML 渲染中将作者呈现为字符串。

<p style="color: white">Authors: {{i['authors']}}</p> 这是我目前拥有的,但它显示为: Authors: ['Bernerd Allmon', 'Jeremy Anderson'] 我希望它显示为: Authors: Bernerd Allmon, Jeremy Anderson 代替。

我该怎么做?

【问题讨论】:

    标签: python mongodb flask jinja2


    【解决方案1】:

    您可以截取您的代码吗?以便我们更好地理解您的代码。

    【讨论】:

      【解决方案2】:

      如果它的列表你可以这样:

       lst= ['Bernerd Allmon', 'Jeremy Anderson']
       author_data=",".join(lst))
      

      它将被打印为

       print(author_data)
       Bernerd Allmon, Jeremy Anderson
      

      你可以传递数据

      【讨论】:

        猜你喜欢
        • 2015-06-12
        • 1970-01-01
        • 2014-10-30
        • 2019-08-08
        • 1970-01-01
        • 2022-01-14
        • 2013-08-14
        • 1970-01-01
        • 2020-08-17
        相关资源
        最近更新 更多