迁移完毕.....舒服

This commit is contained in:
2025-12-23 13:03:36 +08:00
parent 24643b132a
commit 50199ec37f
7 changed files with 109 additions and 50 deletions

75
main.py
View File

@@ -2,7 +2,7 @@ from flask import Flask, render_template, redirect, url_for, send_from_directory
from blueprint.blog_views import blog_bp
from blueprint.study_views import study_bp
from flask_autoindex import AutoIndex
# from blueprint.admin_views import admin_bp
from blueprint.kami_views import kami_bp
import os
import sqlite3
@@ -25,7 +25,7 @@ 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.register_blueprint(kami_bp, url_prefix='/kami')
@app.route('/')
@@ -51,27 +51,64 @@ def close_connection(exception):
def autoindex(path='.'):
return index.render_autoindex(path, template='mirrors.html')
@app.route('/robots.txt/')
def robots():
return send_from_directory(app.static_folder, 'robots.txt')
@app.route('/google02f6a3f6004a32c6.html')
def google02f6a3f6004a32c6():
return send_from_directory(app.static_folder, 'google02f6a3f6004a32c6.html')
@app.errorhandler(400)
def bad_request(error):
return (
'400 Bad Request<br>'
'请求有误,请检查参数是否正确'
'<title>400 Bad Request</title>',
400
)
@app.route('/sitemap.xml/')
def sitemap():
conn = get_owp_db_conn()
sql_posts = "SELECT * from posts;"
posts = conn.execute(sql_posts).fetchall()
conn.close()
template = render_template('sitemap.xml', posts=posts[::-1], base_url="https://open-ww3-project.ww3.tw/blog/")
response = make_response(template)
response.headers['Content-Type'] = 'application/xml'
return response
@app.errorhandler(401)
def unauthorized(error):
return (
'401 Unauthorized<br>'
'请先登录或提供有效凭证'
'<title>401 Unauthorized</title>',
401
)
@app.errorhandler(403)
def forbidden(error):
return (
'403 Forbidden<br>'
'你没有权限访问此资源'
'<title>403 Forbidden</title>',
403
)
@app.errorhandler(404)
def not_found(error):
return (
'404 Not Found<br>'
'这里什么都没有'
'<title>404 Not Found</title>',
404
)
@app.errorhandler(405)
def method_not_allowed(error):
return (
'405 Method Not Allowed<br>'
'请求方法不被允许'
'<title>405 Method Not Allowed</title>',
405
)
@app.errorhandler(500)
def internal_server_error(error):
return (
'500 Internal Server Error<br>'
'服务器开小差了,请稍后再试'
'<title>500 Internal Server Error</title>',
500
)
if __name__ == '__main__':
app.run(host="0.0.0.0", port=8085, debug=True)