2017-02-22 31 views
-5

formssolved flask AttributeError

class AddProcessForm(Form): 
    process_name = StringField('product_name') 
    step_number = StringField('number') 
    step_name = StringField('name') 
    submit = SubmitField('submit') 

views

@manage.route('/admin/process/add', methods=['get', 'post']) 

@csrf.exempt

def add_process(): 
    form = AddProcessForm() 
    if form.validate_on_submit(): 
     print('form',form) 
     print(form.process_name) 
     print(form.step_name) 
     print(form.step_number) 
     print((form.step_name1)) 
     print(form.step_number1) 
     return redirect(url_for('manage.admin')) 
    return render_template("/manage/add_process.html", form=form) 

頁面是可以通過js生成多行step信息,效果如下:

[enter image description here][1] [enter image description here][2] 請問我在麼在服務器拿到step_name,step_number,

+0

I'm voting to close this question as off-topic because it contains Chinese which is not widely understood. – SparkAndShine

+0

Please edit your question and write english sentences, this question is useless to other people not speaking chinese. – NaeiKinDus

回答

0

It is simply because when you are defining AddProcessForm class you are not defining that attribute , If you want to have that attributes, Please define your class like following

class AddProcessForm(Form): 
process_name = StringField('product_name') 
step_number = StringField('number') 
step_name = StringField('name') 
submit = SubmitField('submit') 

adding more attributes to your class

class AddProcessForm(Form): 
process_name = StringField('product_name') 
step_number = StringField('number') 
step_number1 = StringField('number1') 
step_name = StringField('name') 
step_name1 = StringField('name1') 
submit = SubmitField('submit') 

I would suggest do not use attributes like step_number1, if you want multiple fields of same attribute, you can use list instead of defining same attribute with sequence 1,2,3

+0

Hello, thank you for the answer, my question is the user post information is self-growth, I can not predict how many users will step step_number, step_name. –

+0

Thanks please mark it as an answer, you can store list instead of string field to store self-growth information –

+0

please detailed, i don't known –

相關問題