我需要从URL中获取变量并在我的函数中使用它。有人能告诉我我做错了什么吗?
from flask import Flask,jsonify
import json
app = Flask(__name__)
@app.route('/films/<name>')
def show_film(name):
films={'Titanic':1997, 'Transformers':2014, 'X-Men':2014,
'The Wolf of Wall Street':2013, 'Iron Man 3':2013}
for film in films:
if film==name:
NameYear = name + ' was released in '+films[film]
return NameYear
if __name__ == '__main__':
app.run(host='0.0.0.0')
答案 0 :(得分:1)
电影[电影]需要使用str(电影[电影])
转换为字符串或unicode