flask 編寫(xiě)轉(zhuǎn)換器頁(yè)面執(zhí)行時(shí)會(huì)報(bào)類型錯(cuò)誤
精華
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 對(duì)應(yīng)的是 page函數(shù) ,num 對(duì)應(yīng)對(duì)應(yīng)`/page/`中的num,必須是str return 'hello world' if __name__ == '__main__': app.run(port=5000, debug=True)
TypeError: sequence item 1: expected str instance, int found