我正在尝试根据访问的网址动态添加图片,但是当我尝试转到其他网址时,它不会从主图像中更改它。我认为问题在于它正在使用会话并且在整个会话期间保持相同的值。
from flask import Flask, render_template, request, redirect, session, url_for
app = Flask(__name__)
app.secret_key = 'ThisIsSecret'
@app.route('/')
def index():
return render_template('index.html')
@app.route('/ninja')
def allninjas():
session['picture'] = url_for('static', filename='tmnt.png')
return render_template('ninja.html')
@app.route('/ninja/orange')
def orangeninja():
session['picture'] = url_for('static', filename='michelangelo.jpg')
return redirect('/ninja')
@app.route('/ninja/red')
def redninja():
session['picture'] = url_for('static', filename='raphael.jpg')
return redirect('/ninja')
@app.route('/ninja/purple')
def purpleninja():
session['picture'] = url_for('static', filename='donatello.jpg')
return redirect('/ninja')
@app.route('/ninja/blue')
def blueninja():
session['picture'] = url_for('static', filename='leonardo.jpg')
return redirect('/ninja')
app.run(debug=True)