diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b76c873 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +**/__pycache__ +**/*.db +**/*.sql +**/*.db.back +databases/* \ No newline at end of file diff --git a/blueprint/blog_views.py b/blueprint/blog_views.py new file mode 100755 index 0000000..e4e49b1 --- /dev/null +++ b/blueprint/blog_views.py @@ -0,0 +1,29 @@ +from flask import Blueprint, render_template +from database import get_owp_db +import os + + +blog_bp = Blueprint('blog', __name__) + +@blog_bp.route('/') +def home(): + db = get_owp_db() + return render_template('home.html') + +@blog_bp.route('/about/') +def about(): + return render_template('about.html') + pass + +@blog_bp.route('/db_test/') +def test_db(): + db = get_owp_db() + + try: + cur = db.execute('SELECT sqlite_version();') + ver = cur.fetchone()[0] + return f"数据库连接成功!SQLite 版本是: {ver}" + except Exception as e: + return f"连接失败: {str(e)}" + + diff --git a/blueprint/study_views.py b/blueprint/study_views.py new file mode 100755 index 0000000..c7365f3 --- /dev/null +++ b/blueprint/study_views.py @@ -0,0 +1,95 @@ +from flask import Blueprint, render_template, request, url_for, flash, redirect +import os +import sqlite3 + +study_bp = Blueprint('study', __name__) + +def get_db_conn(): + conn = sqlite3.connect('/var/open-ww3-project-ww3-tw/databases/database.db') + conn.row_factory = sqlite3.Row + return conn + +def get_posts(posts_id): + conn = get_db_conn() + posts = conn.execute("SELECT *, datetime(created, '+8 hours') AS created_8 FROM posts WHERE id = ?", (posts_id,)).fetchone() + conn.close() + return posts + +@study_bp.route('/') +def home(): + conn = get_db_conn() + sql = "SELECT *, datetime(created, '+8 hours') AS created_8 FROM posts;" + posts = conn.execute(sql).fetchall() + conn.close() + return render_template('study/home.html', posts=posts[::-1]) + +@study_bp.route('/about/') +def about(): + return render_template('study/about.html') + +@study_bp.route('/posts/') +def show_posts_id(posts_id): + conn = get_db_conn() + posts = get_posts(posts_id) + if posts is None: + return '抱歉,未查到该文章' + + return render_template('study/posts.html', posts=posts) + +@study_bp.route('/posts/new/', methods=('GET', 'POST')) +def new(): + if request.method == "POST": + title = request.form['title'] + content = request.form['content'] + + if not title: + flash('标题不能为空') + elif not content: + flash('内容不能为空') + else: + conn = get_db_conn() + conn.execute('insert into posts (title, content) values (?, ?)', (title, content)) + conn.commit() + conn.close() + flash('文章发布成功') + return redirect(url_for('study.home')) + + return render_template('study/new.html') + +@study_bp.route('/posts//edit', methods=('GET', 'POST')) +def edit_posts_id(posts_id): + if request.method == "POST": + title = request.form['title'] + content = request.form['content'] + + if not title: + flash('标题不能为空') + elif not content: + flash('内容不能为空') + else: + conn = get_db_conn() + conn.execute('update posts set title= ?, content = ? where id = ?', (title, content, posts_id)) + conn.commit() + conn.close() + return redirect(url_for('study.home')) + + return render_template('study/edit.html', posts=posts) + +@study_bp.route('/posts//delete/', methods=['POST' , 'GET']) +def delete_posts_id(posts_id): + if request.method == "POST": + posts = get_posts(posts_id) + conn = get_db_conn() + conn.execute('DELETE FROM posts WHERE id = ?', (posts_id,)) + conn.commit() + conn.close() + flash('删除成功') + return redirect(url_for('study.home')) + + elif request.method == "GET": + posts = get_posts(posts_id) + conn = get_db_conn() + conn.execute('DELETE FROM posts WHERE id = ?', (posts_id,)) + conn.commit() + conn.close() + return render_template('study/delete.html', posts=posts) \ No newline at end of file diff --git a/database.py b/database.py new file mode 100755 index 0000000..8823f07 --- /dev/null +++ b/database.py @@ -0,0 +1,11 @@ +import sqlite3 +from flask import g + +DATABASE_owp = '/var/databases/sqlite/owp.db' + +def get_owp_db(): + db = getattr(g, '_database', None) + if db is None: + db = g._database = sqlite3.connect(DATABASE_owp) + db.row_factory = sqlite3.Row + return db \ No newline at end of file diff --git a/main.py b/main.py new file mode 100755 index 0000000..dfe1d2d --- /dev/null +++ b/main.py @@ -0,0 +1,39 @@ +from flask import Flask, render_template, redirect, url_for, g +from blueprint.blog_views import blog_bp +from blueprint.study_views import study_bp +# from blueprint.admin_views import admin_bp +import os + +app = Flask(__name__, static_url_path='/static/') + +# session +#app.secret_key = "508948973a8651f160baf3b26f18c47d" +app.secret_key = '玩鵬畝遜溉痕叛課還擇鼇粹拜溜泉聰倡效蘭鱅都凍芝西鄂' + + + +# 注册蓝图 +app.register_blueprint(blog_bp, url_prefix='/blog') +app.register_blueprint(study_bp, url_prefix='/study') +# app.register_blueprint(admin_bp, url_prefix='/admin') + + +@app.route('/') +def repage(): + # return '' + return redirect(url_for('study.home')) + + +@app.route('/greet//') +def greet(name): + return f'Hello, {name}!' + +# 全局清理关闭数据库连接 +@app.teardown_appcontext +def close_connection(exception): + db = getattr(g, '_database', None) + if db is not None: + db.close() + +if __name__ == '__main__': + app.run(host="0.0.0.0", port=8085, debug=True) \ No newline at end of file diff --git a/static/css/main.css b/static/css/main.css new file mode 100755 index 0000000..ee6c3a2 --- /dev/null +++ b/static/css/main.css @@ -0,0 +1,58 @@ +/* css页面蓝图 */ + +/* 外部背景 */ +html, body { + height: 100%; + width: 100%; + margin: 0; /*外边框*/ + padding: 0; /*内边框*/ + overflow: hidden; /* 防止滚动条 */ + background-color: #333; /* 背景颜色 */ +} + +/* 内部容器 */ +#app-canvas { + width: 1280px; + height: 800px; + + background-color: rgba(147, 185, 255, 0.644); + border: 5px solid #0056b3; /* 定义边框 5px 实线 蓝色 */ + /* transform-origin: 0 0; /* 定义缩放起点 左上角 */ + + position:fixed; /* 固定页面,不滚动 */ + left: 50%; /* 调整左边缘位置到中央 */ + top: 50%; /* 调整上边缘位置到中央 */ + + padding: 30px; /* 内部间距 30px */ + + +} + +header { + margin-bottom: 30px; /* 外部间距 30px */ + text-align: center; /* 文字居中 */ +} + +h1 { + font-size: 48px; + color: #fff; + text-shadow: 2px 2px 4px rgba(0,0,0,0.5); +} + +#content-area { + display: flex; + justify-content: space-around; + gap: 40px; +} + +/* 自带 */ +.box { + width: 500px; + height: 600px; + background-color: #ffffffcc; + border: 1px solid #ccc; + padding: 20px; + font-size: 20px; + text-align: left; + overflow: auto; +} diff --git a/static/css/style.css b/static/css/style.css new file mode 100755 index 0000000..5d8b238 --- /dev/null +++ b/static/css/style.css @@ -0,0 +1,6 @@ +h1 { + border: 2px; + color:brown; + text-align: center; + padding: 10px; +} \ No newline at end of file diff --git a/static/icon/original.ico b/static/icon/original.ico new file mode 100755 index 0000000..167d718 Binary files /dev/null and b/static/icon/original.ico differ diff --git a/static/img/my_girl.png b/static/img/my_girl.png new file mode 100755 index 0000000..14c967a Binary files /dev/null and b/static/img/my_girl.png differ diff --git a/static/img/open-ww3-project.png b/static/img/open-ww3-project.png new file mode 100755 index 0000000..214e4a8 Binary files /dev/null and b/static/img/open-ww3-project.png differ diff --git a/static/js/main.js b/static/js/main.js new file mode 100755 index 0000000..0076628 --- /dev/null +++ b/static/js/main.js @@ -0,0 +1,29 @@ +// js目前不会,先靠ai + +function resizeCanvas() { + // 定义设计基准尺寸 + const designWidth = 1280; + const designHeight = 800; + + // 获取当前浏览器视口尺寸 + const currentWidth = window.innerWidth; + const currentHeight = window.innerHeight; + + const canvas = document.getElementById('app-canvas'); + + // 计算缩放比例 + const scaleX = currentWidth / designWidth; + const scaleY = currentHeight / designHeight; + const scaleFactor = Math.min(scaleX, scaleY); + + // 确保元素中心与 left: 50%; top: 50%; 对齐 + canvas.style.transform = `translate(-50%, -50%) scale(${scaleFactor})`; +} + +// 首次加载时执行 +document.addEventListener('DOMContentLoaded', resizeCanvas); +// 监听窗口大小变化时执行,保持动态缩放 +window.addEventListener('resize', resizeCanvas); + +// 确保在某些情况下也能正确初始化 +resizeCanvas(); \ No newline at end of file diff --git a/templates/about.html b/templates/about.html new file mode 100755 index 0000000..3613d41 --- /dev/null +++ b/templates/about.html @@ -0,0 +1,13 @@ + + + 不想写了 + + + + 忘记写了 +
+ 所以暂时就不写了 +

2025.08.05

+

over

+ + \ No newline at end of file diff --git a/templates/home.html b/templates/home.html new file mode 100755 index 0000000..562c5e7 --- /dev/null +++ b/templates/home.html @@ -0,0 +1,245 @@ + + + + 首页 | ww3 + + + + + + +
+
+

open-ww3-project

+
+ + + +
+ open-ww3-project-img +
+ + + gitea + + + +
+ +

屑站日志:

+
+ + + + + +
+
+
+ + +
+ "; + // 如果连接成功,但是内部状态有问题 + if ($db->lastErrorCode() !==0) { + // 依旧显示为连接失败 + die("数据库连接失败"); + } + + // 内容区 + // 执行sql命令 查询表单 + $select_id_date_title_from_posts_btos /*查询posts表单中的id date title id从大到小排列*/ = $db->query('SELECT id, date, title FROM posts ORDER BY id DESC'); // 执行查询posts表单中的id date title id从大到小排列的命令 + // 循环 写入 + + echo "

全部文章

"; + echo "
"; + echo "文章如下↓"; + echo "
"; + echo "
"; + + while ($row = $select_id_date_title_from_posts_btos->fetchArray(SQLITE3_ASSOC)) { + + echo "文章id: " . $row['id'] . "
"; + echo $row['date'] . "   " . "文章标题: " . $row['title'] . "
"; + echo "页面跳转

"; + } + + + + // 关闭数据库连接 + $db->close(); + + // 捕获php报错 + } catch (Exception $e) { + // 依旧显示为连接失败 + die("数据库连接失败"); + // 关闭数据库连接 + $db->close(); + } + ?> +
+
+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/study/about.html b/templates/study/about.html new file mode 100755 index 0000000..92d4ce5 --- /dev/null +++ b/templates/study/about.html @@ -0,0 +1,12 @@ +{# 引入base #} +{% extends 'study/base.html' %} + +{# 网站标签 #} +{% block title %} 关于页面 {% endblock %} + +{% block content %} + +大家好...... +没有了 + +{% endblock %} \ No newline at end of file diff --git a/templates/study/base.html b/templates/study/base.html new file mode 100755 index 0000000..508123a --- /dev/null +++ b/templates/study/base.html @@ -0,0 +1,54 @@ +{# base模板 #} + + + + + {% block title %}{% endblock %} + + {# 建立一个url,来源于static文件夹的,文件名字为css文件夹下的style.css #} + + + +
+ + + + + + +
+
+ home +
+
+
+ + about +
+
+ +
+
+ {% for message in get_flashed_messages() %} +
{{ message }}
+ {% endfor %} + + {% block content %} {% endblock %} + + + + \ No newline at end of file diff --git a/templates/study/delete.html b/templates/study/delete.html new file mode 100755 index 0000000..9a7af25 --- /dev/null +++ b/templates/study/delete.html @@ -0,0 +1,5 @@ +确定要删除 "{{ posts['title'] }}" 吗? + +
+ +
\ No newline at end of file diff --git a/templates/study/edit.html b/templates/study/edit.html new file mode 100755 index 0000000..d06557c --- /dev/null +++ b/templates/study/edit.html @@ -0,0 +1,25 @@ +{# 引入base #} +{% extends 'study/base.html' %} + +{# 网站标签 #} +{% block title %} 编辑 "{{ posts['title'] }}" {% endblock %} + +{% block content %} + +
+
+ + + +
+
+ + +
+
+ +
+
+ + +{% endblock %} \ No newline at end of file diff --git a/templates/study/home.html b/templates/study/home.html new file mode 100755 index 0000000..64ff184 --- /dev/null +++ b/templates/study/home.html @@ -0,0 +1,20 @@ +{# 引入base #} +{% extends 'study/base.html' %} + +{# 网站标签 #} +{% block title %}study学习{% endblock %} + +{% block content %} +

学习如何搭建一个blog

+

欢迎访问一个学习如何搭建一个blog的页面

+ + {% for posts in posts %} + + +

{{ posts['title'] }}

+
+ {{ posts['created_8'] }} +
+
+ {% endfor %} +{% endblock %} \ No newline at end of file diff --git a/templates/study/new.html b/templates/study/new.html new file mode 100755 index 0000000..3e23171 --- /dev/null +++ b/templates/study/new.html @@ -0,0 +1,25 @@ +{# 引入base #} +{% extends 'study/base.html' %} + +{# 网站标签 #} +{% block title %} 新建文章 {% endblock %} + +{% block content %} + +
+
+ + + +
+
+ + +
+
+ +
+
+ + +{% endblock %} \ No newline at end of file diff --git a/templates/study/posts.html b/templates/study/posts.html new file mode 100755 index 0000000..6635489 --- /dev/null +++ b/templates/study/posts.html @@ -0,0 +1,19 @@ +{# 引入base #} +{% extends 'study/base.html' %} + +{# 网站标签 #} +{% block title %} {{ posts['title'] }} {% endblock %} + +{% block content %} +

{{ posts['title'] }}

+{{ posts['created_8'] }} + + 编辑 + +
+ +

{{ posts['content'] }}

+ + + +{% endblock %} \ No newline at end of file