M
M
Michael2014-11-27 09:49:36
Flask
Michael, 2014-11-27 09:49:36

How to remove Bad Request?

hello
there is a function

def post(self):

        print(request.form)

         #Если все необхоидмые поля заполнены 
        if request.form['name'] and request.form['lastname'] and request.form['email'] and request.form['password']:
           #Если юзера с таким мылом в базе ещее нет
            if email_exist(request.form['email']) == False:
                #Создаем юзера
                create_user(request.form)
                #проверяем пришли ли чекбоксы и привзяваем их к юзеру в базе
                #========================================================
                if request.form['op1']:

                    fa_roles(request.form['email'], 1)
                    print('op1')
                
                if request.form['op2']:
                    print('op2')
                    fa_roles(request.form['email'], 2)
               

                if request.form['op3']:
                    fa_roles(request.form['email'], 3)
                    print('op3')
                #============================================              
                
                return redirect(url_for('registration.regcomplete'))
            else:
               return render_template('registration.html', error='уже есть такое мыло')

        else:
            return render_template('registration.html', error= 'Заполни все поля')

        return self.get()

The question is, if 1 checkbox arrives, everything falls into a Bad Request, and the necessary records appear in the database, if all three come, then it will normally direct further and everything is in order with the records, why?

#fa_roles
@db_session
def fa_roles(email, role):

    user = User.get(email = email)
    user.roles +=Roles.get(id = role)

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