Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Different database problem, can't get app to run. flask social tutorial

Working in pycharm. The app will run but when i open it in the browser i get the following error.

File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1836, in call return self.wsgi_app(environ, start_response) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1820, in wsgi_app response = self.make_response(self.handle_exception(e)) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1403, in handle_exception reraise(exc_type, exc_value, tb) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise raise value File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1817, in wsgi_app response = self.full_dispatch_request() File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1477, in full_dispatch_request Open an interactive python shell in this framerv = self.handle_user_exception(e) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1381, in handle_user_exception reraise(exc_type, exc_value, tb) File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/_compat.py", line 33, in reraise raise value File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1473, in full_dispatch_request rv = self.preprocess_request() File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/flask/app.py", line 1666, in preprocess_request rv = func() File "/Users/blakebinford/PycharmProjects/untitled/app.py", line 29, in before_request g.db = models.DATABASE.g.db.connect() AttributeError: 'SqliteDatabase' object has no attribute 'g'

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Looking at the last line of the stacktrace:

File "/Users/blakebinford/PycharmProjects/untitled/app.py",
  line 29, in before_request
  g.db = models.DATABASE.g.db.connect()
  AttributeError: 'SqliteDatabase' object has no attribute 'g'

The error is saying the models.DATABASE is an SqliteDatabase object you set up in models and it has no g attribute. That means the "g" cannot follow the "DATABASE".

Line 29 should be more like:

g.db = models.DATABASE.connect()