Forums

Flask-mysql: Configuration question

I am running a web app on pythonanywhere and can't manage to insert new records into a table. I have the same app running locally and it works just fine. So I am wondering if I did not set up the connection properly.

I am using python3.4 and flask-mysql.

Below is my code in the app.py file:

mysql = MySQL(cursorclass=DictCursor)
app = Flask(__name__)
app.secret_key = 'why would I tell you my secret key?'

app.config['MYSQL_DATABASE_USER'] = <username>
app.config['MYSQL_DATABASE_PASSWORD'] = <password>
app.config['MYSQL_DATABASE_DB'] =<username$database_name>
app.config['MYSQL_DATABASE_HOST'] = <'username.mysql.pythonanywhere-services.com'>
mysql.init_app(app)

At the end of the file I have:

python if __name__ == "__main__":
     app.run(debug = True)

Also, I am not getting any "explicit" errors but my INSERT INTO table statements are not updating my tables...(they work just fine in my localhost)

Any suggestions? Thank you

that's weird. maybe do a query and print out the result and see what you get?

alternatively, maybe you dont have any data in your pythonanywhere db or you havnt created a table for your data yet?

@bfg - great suggestion. I added a dummy record to mysql table manually (through the mysql console) and also added a query and a print statement to the index page and it works. It is querying and printing the dummy record I added so that makes me think it is not a problem with the database configuration/connection...but something else with the INSERT INTO table statement or perhaps the jquery.AJAX method I using in the "Sign Up" button.

if you log to see if the insert into statement was ever run, then you can see if maybe the request is being rejected earlier on/if it never got sent to the server.