Skip to content
This repository has been archived by the owner on Jul 30, 2024. It is now read-only.

Basic Peewee Application import order conflict #849

Open
sistemicorp opened this issue Sep 15, 2019 · 2 comments
Open

Basic Peewee Application import order conflict #849

sistemicorp opened this issue Sep 15, 2019 · 2 comments

Comments

@sistemicorp
Copy link

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

@nelsonkam
Copy link

nelsonkam commented Nov 5, 2019

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

@sistemicorp
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

2 participants