Forums

flask and mysql

I am using the free account to test my practice app. I set up mysql in the DATABASE tab. I am using SQLALCHEMY and Flask in the app. Here is my URI in the config.cfg file:

SQLALCHEMY_DATABASE_URI = 'mysql://myusername:mypassword@myusername.mysql.pythonanywhere-services.com/myusername$testing'

my virtual env has Flask and SQLALCHEMY. I opened the console by clicking on the app, then

>>> from app import Books
>>> book1 = Books(title='book12', author='author1', genre='genre1')
>>> book1
 <Books (transient 140258132497024)>
 >>> db.session.add(book1)
 >>> db.session.commit()
 >>> books = Books.query.all()
 >>> books
[<Books 1>, <Books 3>]
>>> for book in books:
     ...     print(book.id, book.title, book.genre, book.author, book.add_date, book.update_date, end='\n')
    ... 
 1 book1 genre1 author1 2020-03-28 01:56:43 2020-03-28 01:56:43
 3 book12 genre1 author1 2020-03-28 03:32:07 2020-03-28 03:32:07
 >>>

First i don't know where mysql db is installed. is there an interface to browse it? 2nd, my app does not work on pythonanywhere. I looked at the error log:

2020-03-28 03:37:12,319: Error running WSGI application
2020-03-28 03:37:12,351: ModuleNotFoundError: No module named 'MySQLdb'

do i need to install anything? please help.

i INSTALLED mysqlclient and it worked: pip install mysqlclient

i don't know where mysql db is installed. is there an interface to browse it? how do i see what is installed in my vitualenv. thanks!

I got my answers after more digging from this article: https://blog.pythonanywhere.com/121/

aha great, thanks for letting us know!