Python Flask-CouchDB - AttributeError: '_AppCtxGlobals' object has no attribute 'couch'
Arup Rakshit
ar at zeit.io
Wed May 1 07:56:01 EDT 2019
Hello,
I started to write a simple todo app with couchcb. But as usual I met an error which a search in the internet could not help. I don’t even know how `g` gets its properties. My app:
from flask import Flask, render_template, request, g
from flaskext.couchdb import CouchDBManager
app = Flask(__name__)
# DB config
app.config['COUCHDB_SERVER'] = 'http://127.0.0.1:5984'
app.config['COUCHDB_DATABASE'] = 'todo-webapp'
@app.route('/')
def index():
print(dir(g))
document = dict(title="Hello", content="Hello, world!")
g.couch['users'] = document
return render_template('index.html')
if __name__ == '__main__':
manager = CouchDBManager()
manager.setup(app)
manager.sync(app)
app.run(debug=True)
And when I refresh the page from http://127.0.0.1:5000/ ,, I get an error:
['__class__', '__contains__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'get', 'pop', 'setdefault']
127.0.0.1 - - [01/May/2019 17:20:13] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
File "/Users/aruprakshit/projects/flask-apps/todo-app/venv/lib/python3.7/site-packages/flask/app.py", line 2309, in __call__
return self.wsgi_app(environ, start_response)
File "/Users/aruprakshit/projects/flask-apps/todo-app/venv/lib/python3.7/site-packages/flask/app.py", line 2295, in wsgi_app
response = self.handle_exception(e)
File "/Users/aruprakshit/projects/flask-apps/todo-app/venv/lib/python3.7/site-packages/flask/app.py", line 1741, in handle_exception
reraise(exc_type, exc_value, tb)
File "/Users/aruprakshit/projects/flask-apps/todo-app/venv/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/Users/aruprakshit/projects/flask-apps/todo-app/venv/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
response = self.full_dispatch_request()
File "/Users/aruprakshit/projects/flask-apps/todo-app/venv/lib/python3.7/site-packages/flask/app.py", line 1815, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/Users/aruprakshit/projects/flask-apps/todo-app/venv/lib/python3.7/site-packages/flask/app.py", line 1718, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/Users/aruprakshit/projects/flask-apps/todo-app/venv/lib/python3.7/site-packages/flask/_compat.py", line 35, in reraise
raise value
File "/Users/aruprakshit/projects/flask-apps/todo-app/venv/lib/python3.7/site-packages/flask/app.py", line 1813, in full_dispatch_request
rv = self.dispatch_request()
File "/Users/aruprakshit/projects/flask-apps/todo-app/venv/lib/python3.7/site-packages/flask/app.py", line 1799, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/Users/aruprakshit/projects/flask-apps/todo-app/app.py", line 14, in index
g.couch['users'] = document
File "/Users/aruprakshit/projects/flask-apps/todo-app/venv/lib/python3.7/site-packages/werkzeug/local.py", line 348, in __getattr__
return getattr(self._get_current_object(), name)
AttributeError: '_AppCtxGlobals' object has no attribute ‘couch'
Can anyone help me to fix this?
Thanks,
Arup Rakshit
ar at zeit.io
More information about the Python-list
mailing list