flask-security
flask-security copied to clipboard
Basic Peewee Application import order conflict
When I try and run the example here I get the following traceback,
Traceback (most recent call last):
File "/home/martin/PycharmProjects/flaskPeewee_01/test.py", line 20, in <module>
class Role(db.Model, RoleMixin):
AttributeError: 'Database' object has no attribute 'Model'
To fix the problem, I changed the import order to,
from flask import Flask, render_template
from peewee import *
from flask_peewee.db import Database
from flask_security import Security, PeeweeUserDatastore, \
UserMixin, RoleMixin, login_required
Versions: flask-peewee==3.0.3 peewee==3.10.0
Hello!
The peewee example from the Flask-Security website is quite outdated. flask-peewee is deprecated. I suggest you try the following snippet:
from peewee import *
from playhouse.flask_utils import FlaskDB
from flask_security import Security, PeeweeUserDatastore, \
UserMixin, RoleMixin, login_required
# Create app
app = Flask(__name__)
app.config['DEBUG'] = True
app.config['SECRET_KEY'] = 'super-secret'
app.config['DATABASE'] = {
'name': 'example.db',
'engine': 'peewee.SqliteDatabase',
}
# Create database connection object
db = FlaskDB(app) # note that I used FlaskDB instead of Database
I made the above changes and my program still works. Thank you.