Commit 2a706cfe authored by Beno Sons's avatar Beno Sons

seed user admin

parent 66308f4a
flask db init flask db init
flask db migrate -m "Initial migration" flask db migrate -m "Initial migration"
flask db upgrade flask db upgrade
flask seed_db
------------------------
flask run --port 5001 --reload flask run --port 5001 --reload
------------------------
SECRET_KEY=your-secret-key SECRET_KEY=your-secret-key
......
...@@ -96,4 +96,9 @@ def create_app(): ...@@ -96,4 +96,9 @@ def create_app():
db.session.rollback() db.session.rollback()
return jsonify({"code": 500, "message": "Internal server error", "data": None}), 500 return jsonify({"code": 500, "message": "Internal server error", "data": None}), 500
@app.cli.command('seed_db')
def seed_db_command():
from app.seeder import seed_users
seed_users()
return app return app
...@@ -3,7 +3,8 @@ from app.models.user import User ...@@ -3,7 +3,8 @@ from app.models.user import User
def seed_users(): def seed_users():
if not User.query.filter_by(username='admin').first(): if not User.query.filter_by(username='admin').first():
admin = User(username='admin', password='admin') admin = User(username='admin')
admin.email = 'admin@example.com' admin.email = 'admin@example.com'
admin.set_password('password')
db.session.add(admin) db.session.add(admin)
db.session.commit() db.session.commit()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment