@app.route('/product/<unique_form>', methods=['GET', 'POST'])
def product(unique_form):
form = ProductForm(**product_data)
class ProductForm(Form):
#form
def __init__(self, *args, **kwargs):
#Here in the __init__ I need to access the unique_form value
Form.__init__(self, *args, **kwargs)
我知道我可以为此使用会话,但是可能存在一种将变量从视图传递到表单类的方法。
像这样:
form = ProductForm(unique_form, **product_data)
这个有可能?
最佳答案
像这样:
@app.route('/product/<unique_form>', methods=['GET', 'POST'])
def product(unique_form):
form = ProductForm(unique_form, **product_data)
class ProductForm(Form):
def __init__(self, unique_form, *args, **kwargs):
# well, now you have unique_form here
Form.__init__(self, *args, **kwargs)