M
M
Michael2016-01-08 21:47:55
Flask
Michael, 2016-01-08 21:47:55

How to do form validation in methodView?

Hello, let's say

@app.route('/', methods ={'GET','POST'])
def app():
    form = Form()
    if request.method =='POST' and form.validate_on_submit():
                                  return redirect('блаблабла')
    else:
        return render_tamplate('in.html',form =form)


Everything is clear here, if the form that came in is valid, then we redirect where the thread is, in all other cases we render the page, either simply with form fields or with fires and validation errors.
actually what is the question, how to do the same with the help of the inheritor of the MethodView class in which get and post are separate class methods that naturally do not save state between requests and and when we redirect from the post method to get if the validation fails so that the user again entered the data, then in the geta a new form is rendered that does not contain old errors. How can I transfer from there?

i.e
class One(MethodWiew):
 def get(self):
# Зесь получам гед запрос и рендерим страницу с формой
    form =FOrm()

    return render template('in.html', form=form)
 def post(self):
# а вот тут получаем запрос пост и если он не проходит валидацю то надо вернуть все то же что и в гет + ошибки валидаторров wtforms

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question