init
This commit is contained in:
26
routes/main.py
Normal file
26
routes/main.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from flask import Blueprint, render_template, redirect
|
||||
|
||||
main_bp = Blueprint('main', __name__)
|
||||
|
||||
@main_bp.route('/')
|
||||
def index():
|
||||
from models import SiteConfig
|
||||
config = {}
|
||||
configs = SiteConfig.query.all()
|
||||
for c in configs:
|
||||
config[c.config_key] = c.config_value
|
||||
return render_template('index.html', config=config)
|
||||
|
||||
@main_bp.route('/favicon.ico')
|
||||
def favicon():
|
||||
"""处理 favicon 请求"""
|
||||
from models import SiteConfig
|
||||
favicon_config = SiteConfig.query.filter_by(config_key='site_favicon').first()
|
||||
if favicon_config and favicon_config.config_value:
|
||||
return redirect(favicon_config.config_value)
|
||||
# 如果没有设置 favicon,尝试使用 logo
|
||||
logo_config = SiteConfig.query.filter_by(config_key='site_logo').first()
|
||||
if logo_config and logo_config.config_value:
|
||||
return redirect(logo_config.config_value)
|
||||
# 返回空响应避免 404
|
||||
return '', 204
|
||||
Reference in New Issue
Block a user