迁移基本完成,还有一些页面需要核对
This commit is contained in:
@@ -1,20 +1,51 @@
|
||||
from flask import Blueprint, render_template
|
||||
from flask import Blueprint, render_template, request, url_for, flash, redirect
|
||||
from database import get_owp_db
|
||||
import os
|
||||
import sqlite3
|
||||
|
||||
def get_owp_db_conn():
|
||||
conn = sqlite3.connect('/var/open-ww3-project-ww3-tw/databases/sqlite/owp.db')
|
||||
conn.row_factory = sqlite3.Row
|
||||
return conn
|
||||
|
||||
blog_bp = Blueprint('blog', __name__)
|
||||
|
||||
@blog_bp.route('/')
|
||||
def home():
|
||||
db = get_owp_db()
|
||||
return render_template('home.html')
|
||||
conn = get_owp_db_conn()
|
||||
sql_logs = "SELECT * from logs;"
|
||||
sql_posts = "SELECT * from posts;"
|
||||
logs = conn.execute(sql_logs).fetchall()
|
||||
posts = conn.execute(sql_posts).fetchall()
|
||||
conn.close()
|
||||
return render_template('home.html', logs=logs[::-1], posts=posts[::-1])
|
||||
|
||||
@blog_bp.route('/about/')
|
||||
def about():
|
||||
return render_template('about.html')
|
||||
pass
|
||||
|
||||
@blog_bp.route('/posts/')
|
||||
def posts_list():
|
||||
conn = get_owp_db_conn()
|
||||
sql_posts = "SELECT * from posts;"
|
||||
posts = conn.execute(sql_posts).fetchall()
|
||||
conn.close()
|
||||
return render_template('list.html', posts=posts[::-1])
|
||||
|
||||
@blog_bp.route('/posts/<int:posts_id>/')
|
||||
def show_posts_id(posts_id):
|
||||
conn = get_owp_db_conn()
|
||||
sql_posts = "SELECT * FROM posts WHERE id = ?"
|
||||
posts = conn.execute(sql_posts, (posts_id,)).fetchone()
|
||||
conn.close()
|
||||
return render_template('posts.html', posts=posts)
|
||||
|
||||
|
||||
|
||||
|
||||
# 数据库测试
|
||||
@blog_bp.route('/db_test/')
|
||||
def test_db():
|
||||
db = get_owp_db()
|
||||
|
||||
Reference in New Issue
Block a user