2015-02-23 60 views
1
@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) 

這是可能的嗎?

回答

3

像這樣:

@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) 
+0

謝謝,完美的作品。我會接受。 – user2990084 2015-02-23 22:46:25