flask 編寫轉換器頁面執(zhí)行時會報類型錯誤
精華
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函數(shù) ,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