flask-security icon indicating copy to clipboard operation
flask-security copied to clipboard

Basic Peewee Application import order conflict

Open sistemicorp opened this issue 6 years ago • 2 comments

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

sistemicorp avatar Sep 15 '19 17:09 sistemicorp

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

nelsonkam avatar Nov 05 '19 02:11 nelsonkam

I made the above changes and my program still works. Thank you.

sistemicorp avatar Nov 05 '19 15:11 sistemicorp