因爲'code'是以下MethodView類的get方法的參數,所以當我調用url_for('c',code ='O7A')時,我期望結果網址爲:/ C/O7Aflask url_for()將查詢字符串當作查詢字符串
而不是預期的價值,我看到的是:?/ C /碼= O7A
from flask import Flask, url_for
from flask.views import MethodView
app = Flask(__name__)
class B(MethodView):
def get(self):
return 'ok'
def post(self):
print url_for('c', code='O7A')
return 'ok'
app.add_url_rule('/b',
view_func=B.as_view('b'),
methods=['GET', 'POST'])
class C(MethodView):
def get(self, code):
return 'ok'
def post(self):
return 'ok'
app.add_url_rule('/c/<code>',
view_func=C.as_view('c'),
methods=['GET'])
app.add_url_rule('/c/',
view_func=C.as_view('c'),
methods=['POST'])
print app.url_map
if __name__ == "__main__":
app.run()