Reputation: 2840
@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)
I know that i can use sessions for this, but probably there is a way of pass the variable from the view to the form class.
Something like this:
form = ProductForm(unique_form, **product_data)
This is possible?
Upvotes: 1
Views: 1466
Reputation: 134038
Like this:
@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)
Upvotes: 3