简体   繁体   English

获取 Python Flask 以从 json/dictionary 返回值

[英]Get Python Flask to return values from json/dictionary

I have stored my output in a dictionary, like this:我已将输出存储在字典中,如下所示:

str3 = "Triangle, Bow, Boat"
str1 = "some text regarding body parts"
str2 = "some text regarding themes"


d={}
key=str3
d[key] = str1
d[key]=[d[key]]
d[key].append(str2)
print(d)

{'Triangle, Bow, Boat': ['some text regarding body parts', 'some text regarding themes']} {'三角形,弓,船':['关于身体部位的一些文字','关于主题的一些文字']}

And I am trying to get it to be returned to html so that it appears separated on three lines as such:我试图让它返回到 html,以便它在三行中分开显示:

Triangle, Bow, Boat some text regarding body parts some text regarding themes三角形、弓、船 一些关于身体部位的文字 一些关于主题的文字

I have tried creating an entire string as output and using new line and break characters, but this didn't work.我尝试创建一个完整的字符串作为输出并使用换行符和换行符,但这不起作用。

So I'm trying to use some combination of jsonify and json.dump in order to get these to display properly in html.所以我试图使用 jsonify 和 json.dump 的某种组合来让它们在 html 中正确显示。

I think you want to do:我想你想做:

string = key + '<br>' + d[key][0] + '<br>' + d[key[1]
return '<p>' + string '</p>'

above code should work with the + sign added上面的代码应该与添加的 + 号一起使用

string = key + '<br>' + d[key][0] + '<br>' + d[key[1]]
return '<p>' + string + '</p>'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM