def val_with_content_type(value, template):
"""Return either json or text/html with value dict."""
mimes = request.accept_mimetypes
json_score = mimes['application/json'] if 'application/json' in mimes else 0
text_html_score = mimes['text/html'] if 'text/html' in mimes else 0
if json_score > text_html_score:
return jsonify(value)
else:
return render_template(template, **value)
评论列表
文章目录