forked from sixu05202004/flaskblog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanager.py
45 lines (35 loc) · 1 KB
/
manager.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
"""
manager.py
~~~~~~~~~~~
flask manager script
:copyright: (c) 2013.
:license: BSD, see LICENSE for more details.
"""
from flask.ext.script import Server, Manager, prompt_bool
from myapp import app
from model import db
manager = Manager(app)
manager.add_command("runserver", Server('0.0.0.0', port=5000))
@manager.command
def createall():
"Creates database tables"
db.create_all()
"add Category"
lists=[u'PYTHON',u'编程珠玑',u'数据库',u'操作系统',u"杂项"]
from model import Category
for i in range(1, 7):
item = Category()
item.id = i
item.category_name = lists[i-1]
db.session.add(item)
db.session.commit()
@manager.command
def dropall():
"Drops all database tables"
if prompt_bool("Are you sure ? You will lose all your data !"):
db.drop_all()
if __name__ == "__main__":
manager.run()