manage.py 754 B

123456789101112131415161718192021222324252627282930313233
  1. from flask.ext.script import Manager, prompt_bool, Shell, Server
  2. from termcolor import colored
  3. from app import app, db, models
  4. manager = Manager(app)
  5. def make_shell_context():
  6. return dict(app=app)
  7. @manager.command
  8. def initdb():
  9. ''' Create the SQL database. '''
  10. db.create_all()
  11. print(colored('The SQL database has been created', 'green'))
  12. @manager.command
  13. def dropdb():
  14. ''' Delete the SQL database. '''
  15. if prompt_bool('Are you sure you want to lose all your SQL data?'):
  16. db.drop_all()
  17. print(colored('The SQL database has been deleted', 'green'))
  18. manager.add_command('runserver', Server())
  19. manager.add_command('shell', Shell(make_context=make_shell_context))
  20. if __name__ == '__main__':
  21. manager.run()