简体   繁体   English

在web.py中返回多行

[英]Return multiple lines in web.py

I got my data out of MySQL using MySQLdb, however when I try to display them in the webpage using web.py with JSON 我使用MySQLdb从MySQL中获取了数据,但是当我尝试使用带有JSON的web.py在网页中显示数据时

fetch_resu = cur.fetchall()
json_list = []
for each_tup in fetch_resu:
    json_list.append(each_tup)
return json.dumps(json_list, encoding="UTF-8", ensure_ascii=False, indent=4, separators=(',', ': '))

I will get a bunch of data stuck in one line in the web page (which same sentence run perfectly in local debugging) 我将在网页的一行中获取大量数据(同一句话在本地调试中可以完美运行)

Since I can only return data, how could I make them prettier? 由于只能返回数据,因此如何使它们更美观? Or shall I use template? 还是我应该使用模板? But my database is dynamicly changing. 但是我的数据库正在动态变化。

IMHO, there are two options. 恕我直言,有两种选择。

  • surround the content with <pre>..</pre> or <code>..</code> <pre>..</pre><code>..</code>包围内容

OR 要么

  • respond as a text/plain content-type: text/plain内容类型进行响应:

     web.header('Content-Type', 'text/plain') return json.dumps(...) 

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

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