Hey there, I'm fresh to the python/web scene and typically work in C#/desktop app space and need to deploy a database with a rest api for basic queries using our website on PA.
I'm mostly referencing code here https://blog.pythonanywhere.com/121/ but haven't been able to get it to stick.
Here's my setup code.....
from flask_sqlalchemy import SQLAlchemy
import sys
import json
import datetime
GLOBAL_CONTEXT = {}
SECTION_NAMES = ["home", "about", "sectors", "products", "services", "news"]
ARTICLE_LIST = []
BLURBS = {}
APP = Flask(__name__)
SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://{username}:{password}@{hostname}/{databasename}".format(
username="########",
password="########",
hostname="jelec.mysql.pythonanywhere-services.com",
databasename="########$########",
)
APP.config["SQLALCHEMY_DATABASE_URI"] = SQLALCHEMY_DATABASE_URI
APP.config["SQLALCHEMY_POOL_RECYCLE"] = 299
APP.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db = SQLAlchemy(APP)
class jexuser(db.Model):
__tablename__ = "clients"
userId = db.Column(db.Integer, primary_key=True)
userName = db.Column(db.String(4096))
userPass = db.Column(db.String(4096))
content = db.Column(db.String(4096))
And here's my exec code...
@APP.route("/jex/v1/clients", methods=["GET"])
def api_clients():
if 'user' in request.args:
user_name = request.args['user']
query = db.session.query("SELECT * FROM clients WHERE UserName = '{name}';".format(name=user_name))
result = query.first()
return result
else:
return "Error: provide a username."
Here's the error... along with a tall stack which is not included..
ModuleNotFoundError: No module named 'mysql'</code>
... Sorry for the terrible formatting, The forum doesn't seem to have good support for it.
Anyway I'm not sure why the system can't find mysql, any idea whats going on here? Thanks.
[edit by admin: formatting]