I run this application but it is not connecting to MySQL database. I am using Python version 3.7.4 and Flask-SQLAlchemy version 2.4.1
from flask import Flask , render_template, request
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:@localhost/codingthunder'
db = SQLAlchemy(app)
class Contacts(db.Model): **# Table in database = contacts**
sno = db.Column(db.Integer , primary_key=True) **# sno = Primary key**
name = db.Column(db.String(80),unique=False, nullable=False)
def __repr__(self):
return f"<User> {self.name}"
@app.route("/") #defining route
def home():
return render_template("/index.html")
@app.route("/contact" , methods = ['GET','POST'])
def contact():
if request.method == 'POST':
entry = Contacts(name = "ashfaq")
db.session.add(entry)
db.session.commit()
return render_template("contact.html")
app.run(debug = True)
And the Error is ModuleNotFoundError: No module named 'MySQLdb'