Forums

Flask with SQL

I have removed the sql parts with @, whenever I use it I receive this log output:

2015-09-05 06:42:40,599 :ImportError: No module named flask.ext.mysql https://www.pythonanywhere.com/user/GovernIT/files/var/log/governit.pythonanywhere.com.error.log

However I have already installed the flask mysql using pip

from flask import Flask, render_template, json, request
#from flask.ext.mysql import MySQL
from werkzeug import generate_password_hash, check_password_hash


app = Flask(__name__)
#mysql = MySQL()

# MySQL configurations
#app.config['MYSQL_DATABASE_USER'] = '*****'
#app.config['MYSQL_DATABASE_PASSWORD'] = '*****'
#app.config['MYSQL_DATABASE_DB'] = 'GovernIT$default'
#app.config['MYSQL_DATABASE_HOST'] = 'GovernIT.mysql.pythonanywhere-services.com'
#mysql.init_app(app)


@app.route('/')
def main():
    return render_template('signup.html')

if __name__ == "__main__":
    app.run()

I think you will need to create a VirtualEnv, and then install Flask and Flask-MySQLdb into there. Right now, PythonAnywhere is looking in its default Flask libraries, and not seeing Flask-MySQLdb in there.

I may, however, be wrong. But that's what I'd try.

Could you help me with that?

So currently I have: .cache/
.local/
.virtualenvs/
governitapp/
mysite/
venv/

I have created the virtual environment. Mysite/ contains my python code and my static and templates

hi there,

If you look at your webapps tab, you will see that your virtualenv config has an error.

In particular, you are trying to run a python2.7 virtualenv with python3.4

I would advise you to abandon your current virtualenv and create a new one, this time making sure to use

mkvirtualenv my-new-virtualenv --python=/usr/bin/python3.4

to specify that you are creating a python3.4 virtualenv

I did a pip install of flask_mysqldb in my virtualenv and checked the python version 3.6 which works in my local system, but still I get the below error: Error running WSGI application ModuleNotFoundError: No module named 'flask_mysqldb' Any inputs?

Do you have your web app configured to use that virtualenv?