Import view.py with some changes from lilydjwg/couchdb-python3