I'm making a dbms project on a covid hospital system and I can't seem to figure out why i'm getting this error, here's my code:
from flask import Flask,redirect,render_template,request
from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin
from flask_login import login_required,logout_user,login_user,login_manager,LoginManager,current_user
#database connection
local_server=True
app=Flask(__name__)
app.secretkey="adarshacharya"
#unique access
login_manager=LoginManager()
login_manager.init_app(app)
login_manager=login_view='login'
app.config["SQLALCHEMY_DATABASE_URI"]='mysql://root:@localhost/covidata'
db=SQLAlchemy(app)
@login_manager.user_loader
def load_user(user_id):
return patient_details.query.get(int(user_id))
class patient_details(db.Model):
pid=db.Column(db.Integer, primary_key=True)
Email=db.Column(db.String(50),unique=True)
Password=db.Column(db.String(50))
FirstName=db.Column(db.String(50))
LastName=db.Column(db.String(50))
Contact=db.Column(db.String(10),unique=True)
Age=db.Column(db.Integer)
@app.route("/")
def home():
return render_template("index.html")
@app.route("/patientregistration")
def PatientRegistration():
return render_template('patientregistration.html')
@app.route("/patientlogin")
def PatientLogin():
return render_template('patientlogin.html')
@app.route('/registration',methods=['POST','GET'])
def registration():
if request.method=="POST":
patientid=request.form.get('Pid')
pemail=request.form.get('Pemail')
ppassword=request.form.get('PPassword')
pfirstname=request.form.get('PFirstName')
plastname=request.form.get('PLastName')
pcontact=request.form.get('PContact')
page=request.form.get('PAge')
print(patientid,pemail,ppassword,pfirstname,plastname,pcontact,page)
return render_template("patientregistration.html")
app.run(debug=True)
And this is the error:
@login_manager.user_loader AttributeError: 'str' object has no attribute 'user_loader' `
I've tried all fixes i've come across but those don't seem to fix the problem :(, any help would be appreciated
CodePudding user response:
Your problem is probably at this line,
login_manager=login_view='login'
change it to,
login_manager.login_view='login'
CodePudding user response:
try passing "UserMixin" as an argument to the patient_details object
class patient_details(db.Model, UserMixin):
pid = db.Column(db.Integer, primary_key=True)
Email = db.Column(db.String(50),unique=True)
Password = db.Column(db.String(50))
FirstName = db.Column(db.String(50))
LastName = db.Column(db.String(50))
Contact = db.Column(db.String(10),unique=True)
Age = db.Column(db.Integer)
Also try the solution given by Charles