- 前台页面全面升级为Tailwind CSS框架 - 引入Google Fonts (Space Grotesk, Noto Sans) - 主色调更新为#25c0f4 (cyan blue) - 实现玻璃态效果和渐变背景 - 优化首页网格卡片布局和悬停动画 - 优化详情页双栏布局和渐变Logo光晕 - 优化管理员登录页,添加科技网格背景 - Flask-Admin后台完整深色主题 - 统一Material Symbols图标系统 - 网站自动抓取功能界面优化 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
118 lines
5.1 KiB
Python
118 lines
5.1 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""
|
||
数据库初始化脚本
|
||
用于创建数据库表和初始化示例数据
|
||
"""
|
||
|
||
import os
|
||
import sys
|
||
from app import create_app
|
||
from models import db, Site, Tag, Admin
|
||
|
||
# 设置UTF-8编码输出
|
||
if sys.platform.startswith('win'):
|
||
import io
|
||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||
|
||
def init_database():
|
||
"""初始化数据库"""
|
||
app = create_app('development')
|
||
|
||
with app.app_context():
|
||
print("正在创建数据库表...")
|
||
# 删除所有表(开发环境)
|
||
db.drop_all()
|
||
# 创建所有表
|
||
db.create_all()
|
||
print("✓ 数据库表创建成功")
|
||
|
||
# 创建默认管理员
|
||
print("\n正在创建默认管理员...")
|
||
admin = Admin(
|
||
username='admin',
|
||
email='admin@example.com',
|
||
is_active=True
|
||
)
|
||
admin.set_password('admin123') # 默认密码
|
||
db.session.add(admin)
|
||
print("✓ 默认管理员创建成功")
|
||
print(" 用户名: admin")
|
||
print(" 密码: admin123")
|
||
|
||
# 创建示例标签
|
||
print("\n正在创建示例标签...")
|
||
tags_data = [
|
||
{'name': 'AI对话', 'slug': 'ai-chat', 'description': 'AI聊天和对话工具', 'icon': 'fas fa-comments', 'sort_order': 100},
|
||
{'name': '图像生成', 'slug': 'image-gen', 'description': 'AI图像生成和编辑工具', 'icon': 'fas fa-image', 'sort_order': 90},
|
||
{'name': '视频制作', 'slug': 'video', 'description': 'AI视频生成和编辑工具', 'icon': 'fas fa-video', 'sort_order': 80},
|
||
{'name': '写作助手', 'slug': 'writing', 'description': 'AI写作和文本生成工具', 'icon': 'fas fa-pen', 'sort_order': 70},
|
||
{'name': '代码助手', 'slug': 'coding', 'description': 'AI编程和代码生成工具', 'icon': 'fas fa-code', 'sort_order': 60},
|
||
{'name': '音频处理', 'slug': 'audio', 'description': 'AI音频生成和处理工具', 'icon': 'fas fa-music', 'sort_order': 50},
|
||
]
|
||
|
||
tags = []
|
||
for tag_data in tags_data:
|
||
tag = Tag(**tag_data)
|
||
db.session.add(tag)
|
||
tags.append(tag)
|
||
db.session.commit()
|
||
print(f"✓ 创建了 {len(tags)} 个示例标签")
|
||
|
||
# 创建示例网站
|
||
print("\n正在创建示例网站...")
|
||
sites_data = [
|
||
{
|
||
'name': 'ChatGPT',
|
||
'url': 'https://chat.openai.com',
|
||
'slug': 'chatgpt',
|
||
'short_desc': '最强大的AI对话助手,可以回答问题、写作、编程等',
|
||
'description': 'ChatGPT是OpenAI开发的大型语言模型,能够进行自然对话、回答问题、协助写作、编程等多种任务。它基于GPT-4架构,拥有强大的理解和生成能力。',
|
||
'features': '• 自然语言对话\n• 代码编写和调试\n• 文章写作和润色\n• 数据分析\n• 创意头脑风暴',
|
||
'tags': [tags[0], tags[3], tags[4]],
|
||
'sort_order': 100
|
||
},
|
||
{
|
||
'name': 'Midjourney',
|
||
'url': 'https://www.midjourney.com',
|
||
'slug': 'midjourney',
|
||
'short_desc': '顶级AI绘画工具,可以根据文字描述生成精美图片',
|
||
'description': 'Midjourney是一款强大的AI图像生成工具,通过简单的文字描述就能创作出高质量的艺术作品。支持多种艺术风格,广泛应用于设计、插画等领域。',
|
||
'features': '• 文字转图像\n• 多种艺术风格\n• 高清图片输出\n• 图片变体生成\n• 社区画廊',
|
||
'tags': [tags[1]],
|
||
'sort_order': 95
|
||
},
|
||
{
|
||
'name': 'GitHub Copilot',
|
||
'url': 'https://github.com/features/copilot',
|
||
'slug': 'github-copilot',
|
||
'short_desc': 'AI编程助手,帮助你更快地编写代码',
|
||
'description': 'GitHub Copilot是由GitHub和OpenAI联合开发的AI编程助手,可以根据上下文自动建议代码补全,支持多种编程语言。',
|
||
'features': '• 智能代码补全\n• 多语言支持\n• 函数生成\n• 代码注释生成\n• IDE集成',
|
||
'tags': [tags[4]],
|
||
'sort_order': 85
|
||
},
|
||
]
|
||
|
||
for site_data in sites_data:
|
||
site = Site(**site_data)
|
||
db.session.add(site)
|
||
db.session.commit()
|
||
print(f"✓ 创建了 {len(sites_data)} 个示例网站")
|
||
|
||
print("\n" + "="*50)
|
||
print("数据库初始化完成!")
|
||
print("="*50)
|
||
print("\n你可以使用以下命令启动应用:")
|
||
print(" python app.py")
|
||
print("\n然后访问:")
|
||
print(" 前台: http://localhost:5000")
|
||
print(" 后台: http://localhost:5000/admin")
|
||
print(" 登录: http://localhost:5000/admin/login")
|
||
print("\n管理员账号:")
|
||
print(" 用户名: admin")
|
||
print(" 密码: admin123")
|
||
print("\n⚠️ 请在生产环境中修改默认密码!")
|
||
|
||
if __name__ == '__main__':
|
||
init_database()
|