from flask import Flask app = Flask(__name__) @app.context_processor def inject_global_variables(): return {'site_name': 'My Website'} @app.route('/') def index(): return render_template('index.html')
模版中使用site_name全局变量
<!DOCTYPE html> <html> <head> <title>{{ site_name }}</title> </head> <body> {% block content %} {% endblock %} </body> </html>
标签:name,flask,模版,app,site,全局变量 From: https://www.cnblogs.com/fyiyy/p/17804399.html