Files
open-ww3-project-ww3-tw/blueprint/index_views.py

45 lines
1.2 KiB
Python

from flask import Blueprint, render_template, url_for, redirect
import sqlite3
import os
index_bp = Blueprint('/', __name__)
db_path = "/var/open-ww3-project-ww3-tw/databases/sqlite/owp.db"
def get_paint_db_conn():
conn = sqlite3.connect(db_path)
conn.row_factory = sqlite3.Row
return conn
@index_bp.route('/')
def repage():
return redirect(url_for('blog.home'))
@index_bp.route('/mirrors/')
def mirrors():
return redirect(url_for('blog.autoindex'))
@index_bp.route('/greet/<name>/')
def greet(name):
return f'Hello, {name}!'
@index_bp.route('/paint/')
def paint_home():
conn = get_paint_db_conn()
select_sql = "SELECT * FROM paint;"
data = conn.execute(select_sql).fetchall()
conn.close()
# 展示图片
img_url = "https://open-ww3-project.ww3.tw/blog/folders/paint/new/"
# 查询tags和class
db_cursor = sqlite3.connect(db_path).cursor()
tags_sql = "SELECT DISTINCT tags FROM paint;"
class_sql = "SELECT DISTINCT class FROM paint;"
for class_data in db_cursor.execute(class_sql).fetchall():
for tags_data in db_cursor.execute(tags_sql).fetchall():
return render_template('paint/home.html', data = data, tags_data = tags_data[0], class_data = class_data[0], img_url = img_url)