M
M
Michael2014-05-25 13:16:05
Flask
Michael, 2014-05-25 13:16:05

How to add a variable to a class?

hello

there is a class

class RestoreView(FlaskView):

    restore =True
    error = ''
    form = RestorePwdForm()

    def get(self):
        return render_template('login.html', form =self.form, restore=self.restore, error =self.error)

    def post(self):


        print(request.form)

        if request.form:
            try:
              a= resetpwd(request.form['email'])
              print(a)
              self.error = 'Ваш новый пароль {0}'.format(a)
            except:
              self.error ="ИДИ ОТСЮДА"
        return redirect(url_for('RestoreView:get'))


in this form, the error raise RuntimeError ('working outside of application context')
RuntimeError: working outside of application context falls out

if you remove variable declarations at the beginning, everything works, why?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Solovyov, 2014-05-25
@nextel

transfer form = RestorePwdForm() to the def get method, the error tells you working outside of application context that you are creating an object outside the context.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question