话题 首页 > Python2 教程微课讨论区> 小题讨论区> 详情

flask 编写转换器页面执行时会报类型错误

精华
学号:1666652 2020-02-11 20:36:35 浏览(2235) 回复(0) 赞(0)
from flask import Flask, url_for from werkzeug.routing import BaseConverter class MyIntConverter(BaseConverter): def __init__(self, url_map): super(MyIntConverter, self).__init__(url_map) def to_python(self, value): return int(value) def to_url(self, value): return value * 2 app = Flask(__name__) app.url_map.converters['my_int'] = MyIntConverter @app.route('/page/') def page(num): print(num) print(url_for('page', num='145')) # page 对应的是 page函数 ,num 对应对应`/page/`中的num,必须是str return 'hello world' if __name__ == '__main__': app.run(port=5000, debug=True) TypeError: sequence item 1: expected str instance, int found
python flask

回答(0)

要回复,请先登录 或者注册