我正在使用 Flask 创建一个 API,并具有以下代码:
@app.route('/<major>/')
def major_res(major):
course_list = list(client.db.course_col.find({"major": (major.encode("utf8", "ignore").upper())}))
return json.dumps(course_list, sort_keys=True, indent=4, default=json_util.default)
在/csci/
浏览器中查看时,输出如下所示:
[{ "course": "CSCI052", "description": "Fundamentals of Computer Science. A solid foundation in functional programming, procedural and data abstraction, recursion and problem-solving. Applications to key areas of computer science, including algorithms and complexity, computer architecture and organization, programming languages, finite automata and computability. This course serves the same role as HM 60 as a prerequisite for upper-division computer science courses at any of the Claremont Colleges. Prerequisite: 51.", "instructor": "Bull, Everett L.,, Jr.", "name": " Fundamentals of Computer Science", "number": 52, "school": "PO" }]
如何返回这本字典,以便每个键和值都在自己的行上?