0

new to python. Following a couple tutorials to serve an application (ddworkflow.com) using Python 3.6.7, Flask, Gunicorn, NGINX, and MySQL on Ubuntu 18.04

The tutorials are:

https://philchen.com/2019/02/11/how-to-make-a-python-web-app-in-virtualenv-using-flask-gunicorn-nginx-on-ubuntu-18-04

and

https://code.tutsplus.com/tutorials/creating-a-web-app-from-scratch-using-python-flask-and-mysql--cms-22972

I got through the first tutorial and am able to successfully serve the basic web pages from the second tutorial.

Installing everything in a virtual environment and just installed flask-mysql using pip install flask-mysql.

My pip freeze shows:

Click==7.0
Flask==1.0.2
Flask-MySQL==1.4.0
itsdangerous==1.1.0
Jinja2==2.10
MarkupSafe==1.1.0
PyMySQL==0.9.3
Werkzeug==0.14.1

After installing Flask-MySQL I tested the installation by trying the following different variations of the "from" command (at the python prompt):

  1. from flask.ext.mysql import MySQL
  2. from flaskext.mysql import MySQL
  3. from flask_mysql import MySQL
  4. from flaskext.mysql import MySQL

1, 2, and 3 all produce ModuleNotFoundError... The only one that does not throw an error is from flaskext.mysql import MySQL

However, when I add from flaskext.mysql import MySQL to my flask app file (app01.py) I immediately get a 502 bad gateway error. My app01.py file is

from flask import Flask, render_template, json, request
#from flaskext.mysql import MySQL #<--comment out or get 502 error   
hello = Flask(__name__)

@hello.route("/")
def greeting():
    return render_template('index.html')

@hello.route('/showSignUp')
def showSignUp():
    return render_template('signup.html')

@hello.route('/signUp',methods=['POST'])
def signUp(): 
    # read the posted values from the UI
    _name = request.form['inputName']
    _email = request.form['inputEmail']
    _password = request.form['inputPassword']

    # validate the received values
    if _name and _email and _password:
        return json.dumps({'html':'<span>All fields good !!</span>'})
    else:
        return json.dumps({'html':'<span>Enter the required fields</span>'})

if __name__ == "__main__":
    hello.run(host='0.0.0.0')

Any help getting the 502 error to go away so that I connect to the database is much appreciated. Thank you.

JeffA
  • 166
  • 1
  • 17

1 Answers1

0

This could be a virtualenv error, check out this link: https://www.pythonanywhere.com/forums/topic/2877/

Very similar question from earlier: ImportError: No module named flask.ext.mysql

Kata
  • 142
  • 1
  • 7
  • Thanks. I'll try that and report back. Cheers. – JeffA Feb 22 '19 at 03:10
  • Thanks but does not appear to be the issue. Flask app load ok when importing SQLalchemy but fails on MySQL Next step is testing SQL alchemy (probsbly preferable). – JeffA Mar 02 '19 at 00:35