Tôi có ứng dụng Google App Engine thực hiện yêu cầu BigQuery. Tôi sử dụng json.dumps
để xử lý dữ liệu và hiện tôi đang cố chuyển đối tượng JSON sang mẫu HTML để gửi qua email. Tôi đã tìm thấy mô-đun Python này, json2html, mà tôi muốn sử dụng nhưng tôi nhận được thông báo lỗi
ImportError Không có mô-đun nào có tên json2html
kết quả BigQuery
[
{'Color': u'red', 'Date': '12/12/12', 'Id': 188},
{'Color': u'orange', 'Date': '03/25/12', 'Id': 360},
{'Color': u'yellow', 'Date': '08/17/12', 'Id': 258},
{'Color': u'green', 'Date': '01/02/12', 'Id': 291},
{'Color': u'red', 'Date': 'N/A', 'Id': 895},
{'Color': u'blue', 'Date': 'N/A', 'Id': 347},
{'Color': u'orange', 'Date': 'N/A', 'Id': 923}
]
con trăn
import json
from json2html import *`
def myfunction[self]:
items = Item.query[].fetch[]
my_list = []
for x in items:
....
my_list.append[]
result = json.dumps[my_list, default=str, sort_keys=True, indent=4]
conv_result = json2html.convert[result]
return conv_result
def get[self]:
my_results = self.myfunction[]
send_message['{}@appspot.gserviceaccount.com'.format[
app_identity.get_application_id[]], my_results]
self.response.content_type = 'text/plain'
Những gì tôi đã làm cho đến nay
Tôi không chắc liệu sự cố này có liên quan đến Google App Engine theo bất kỳ cách nào hay sự cố có thể là gì không. Bất kỳ ý tưởng?
Một thẻ đã tồn tại với tên chi nhánh được cung cấp. Nhiều lệnh Git chấp nhận cả tên thẻ và tên nhánh, vì vậy việc tạo nhánh này có thể gây ra hành vi không mong muốn. Bạn có chắc chắn muốn tạo nhánh này không?
Dưới đây là các ví dụ về python api json2html. json2html. chuyển đổi được lấy từ các dự án mã nguồn mở. Bằng cách bỏ phiếu, bạn có thể chỉ ra ví dụ nào hữu ích và phù hợp nhất
1 Ví dụ 7
0
ví dụ 1
Dự án. sondra
Giấy phép. Xem giấy phép
Tệp nguồn. html. p
def __call__[self, reference, results, **kwargs]:
# handle indent the same way python's json library does
if 'indent' in kwargs:
kwargs['indent'] = int[kwargs['indent']]
if 'ordered' in kwargs:
ordered = bool[kwargs.get['ordered', False]]
del kwargs['ordered']
else:
ordered = False
# fetch a foreign key reference and append it as if it were part of the docuement.
if 'fetch' in kwargs:
fetch = kwargs['fetch'].split[',']
del kwargs['fetch']
else:
fetch = []
if 'bare_keys' in kwargs:
bare_keys = bool[kwargs.get['bare_keys', False]]
del kwargs['bare_keys']
else:
bare_keys = False
# note this is a closure around the fetch parameter. Consider before refactoring out of the method.
def serialize[doc]:
if isinstance[doc, docuement.Docuement]:
ret = doc.json_repr[ordered=ordered, bare_keys=bare_keys]
for f in fetch:
if f in ret:
if isinstance[doc[f], list]:
ret[f] = [d.json_repr[ordered=ordered, bare_keys=bare_keys] for d in doc[f]]
elif isinstance[doc[f], dict]:
ret[f] = {k: v.json_repr[ordered=ordered, bare_keys=bare_keys] for k, v in doc[f].items[]}
else:
ret[f] = doc[f].json_repr[ordered=ordered, bare_keys=bare_keys]
return ret
else:
return doc
result = mapjson[serialize, results] # make sure to serialize a full Docuement structure if we have one.
if not [isinstance[result, dict] or isinstance[result, list]]:
result = {"_": result}
from json2html import json2html
rsp = StringIO[]
rsp.write["""
"""]
rsp.write[json2html.convert[json=result, table_attributes="class=\"table table-bordered table-hover\""]]
rsp.write['']
return 'text/html',rsp.getvalue[]
Danh mục python Thẻ python