-
Notifications
You must be signed in to change notification settings - Fork 28
/
manage.py
30 lines (22 loc) · 863 Bytes
/
manage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from flask_script import Manager, Server
from app import create_app
from app.models import User, Post
from werkzeug.security import generate_password_hash
app = create_app()
manager = Manager(app)
manager.add_command("runserver",
Server(host='0.0.0.0',
port=5000,
use_debugger=True))
@manager.option('-u', '--name', dest='name', default='admin')
@manager.option('-p', '--password', dest='password', default='123456')
def create_admin(name, password):
admin = User(name=name, password=generate_password_hash(password))
admin.save()
@manager.command
def add_post():
user = User.objects(name="admin").first()
post = Post(title="Hello", content="Hello Wolrd", author=user, tags=['python', 'flask'],status=1)
post.save()
if __name__ == '__main__':
manager.run()