PythonAnywhere how-to docs

The general, how-to-use PythonAnywhere document for everyone is this:

Deploy a Flask app on PythonAnywhere

The document with instructions for using a MySQL database both in XAMPP (local) and on PythonAnywhere is this:

PythonAnywhere + a MySQL Database

Update: My GitHub repo for using a MySQL database includes a README with instructions.

The key to getting the MySQL db to work exactly the same in both places is to use the SQLAlchemy methods and functions for reading from (and writing to, if needed) your database. If you use PyMySQL methods, they will not work at PythonAnywhere unless you set up a virtualenv at PythonAnywhere and install PyMySQL there. (You can do that if you want to.)

The Flask-SQLAlchemy docs can be used in conjunction with Grinberg’s book to read from and write to your MySQL database. In particular you will want to master the syntax for querying records in your database.

NOTE: We never use many of the common SQLAlchemy things — such as engine = create_engine() — because Flask-SQLAlchemy (which we are using with Flask) does not require them. If you read the SQLAlchemy docs, make sure you are not adding stuff that the Flask version does not use. In fact, I found the SQLAlchemy docs to be unhelpful. The Flask-SQLAlchemy docs are, on the other hand, very helpful!

Using a MySQL database is optional for the project. You can use SQLite as described in Grinberg’s chapter 5. You can use a Python data file, as you did for Assignment 10.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s