def add_user(userid, password): user = User.query.filter(User.userid == userid).first() if user is not None: return print('ユーザ"{}"追加'.format(userid)) user = User(userid=userid) user.set_password(password) user.enabled = True user.admin = True user.staff = True db.session.add(user) db.session.commit()
from getpass import getpass from flask import current_app as app from flaskr import db from flaskr.models import User username = input("Username: "******"Password: "******"Repeat password: "******"Passwords are not the same") password = getpass("Password: "******"Repeat password: "******"Name of a photo file: ") db.session.add(user) try: db.session.commit() print("Admin added successfully!") except: db.session.rollback() print("Adding failed :(")