迁移基本完成,还有一些页面需要核对
This commit is contained in:
38
main.py
38
main.py
@@ -1,11 +1,21 @@
|
||||
from flask import Flask, render_template, redirect, url_for, g
|
||||
from flask import Flask, render_template, redirect, url_for, send_from_directory, make_response, g
|
||||
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
|
||||
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
|
||||
|
||||
app = Flask(__name__, static_url_path='/static/')
|
||||
|
||||
index_path = '/var/open-ww3-project-ww3-tw/mirrors/'
|
||||
index = AutoIndex(app, browse_root=index_path, add_url_rules=False)
|
||||
|
||||
# session
|
||||
#app.secret_key = "508948973a8651f160baf3b26f18c47d"
|
||||
app.secret_key = '玩鵬畝遜溉痕叛課還擇鼇粹拜溜泉聰倡效蘭鱅都凍芝西鄂'
|
||||
@@ -21,7 +31,7 @@ app.register_blueprint(study_bp, url_prefix='/study')
|
||||
@app.route('/')
|
||||
def repage():
|
||||
# return '<meta http-equiv="refresh" content="0.1;url=/blog/">'
|
||||
return redirect(url_for('study.home'))
|
||||
return redirect(url_for('blog.home'))
|
||||
|
||||
|
||||
@app.route('/greet/<name>/')
|
||||
@@ -35,5 +45,29 @@ def close_connection(exception):
|
||||
if db is not None:
|
||||
db.close()
|
||||
|
||||
|
||||
@app.route('/mirrors/')
|
||||
@app.route('/mirrors/<path:path>')
|
||||
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('/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
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host="0.0.0.0", port=8085, debug=True)
|
||||
Reference in New Issue
Block a user