migrate_pages.py 1006 B

123456789101112131415161718192021222324252627
  1. from app import create_app, db
  2. from app.models import PageContent
  3. app = create_app()
  4. with app.app_context():
  5. db.create_all()
  6. defaults = [
  7. {'key': 'products', 'name': '产品', 'content': '<p>暂无内容,请在后台添加</p>'},
  8. {'key': 'solutions', 'name': '解决方案', 'content': '<p>暂无内容,请在后台添加</p>'},
  9. {'key': 'education', 'name': '产教融合', 'content': '<p>暂无内容,请在后台添加</p>'},
  10. {'key': 'service', 'name': '产业服务', 'content': '<p>暂无内容,请在后台添加</p>'}
  11. ]
  12. for item in defaults:
  13. existing = PageContent.query.filter_by(page_key=item['key']).first()
  14. if not existing:
  15. new_page = PageContent(
  16. page_key=item['key'],
  17. page_name=item['name'],
  18. content=item['content']
  19. )
  20. db.session.add(new_page)
  21. db.session.commit()
  22. print("Page contents initialized successfully.")