我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用app.app.forms()。
def signup(): from forms import SignupForm form = SignupForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data.lower()).first() if user is not None: form.email.errors.append("The Email address is already taken.") return render_template('signup.html', form=form) newuser = User(form.firstname.data,form.lastname.data,form.email.data,form.password.data) db.session.add(newuser) db.session.commit() session['email'] = newuser.email return redirect(url_for('login')) return render_template('signup.html', form=form)
def login(): if g.user is not None and g.user.is_authenticated: return redirect(url_for('index')) from app.forms import LoginForm form = LoginForm() if form.validate_on_submit(): session['remember_me'] = form.remember_me.data user = User.query.filter_by(email=form.email.data.lower()).first() if user and user.check_password(form.password.data): session['email'] = form.email.data login_user(user,remember=session['remember_me']) return redirect(url_for('index')) else: return render_template('login.html',form=form,failed_auth=True) return render_template('login.html',form=form)
def upload(): from app.forms import UploadForm form = UploadForm() if form.validate_on_submit(): action_msg = uploadFile(form.ros_file.data, form.manifest_file.data, form.comments.data) action_list = action_msg.split(";") if len(action_list) != 2: action_error_msg = action_list[0] else: action_error_msg = action_list[0] proxy_name = action_list[1] url_base = url() succeed = (action_error_msg == "None") if succeed == True: return render_template('download.html',download_url = "download/"+proxy_name) else: return render_template('upload.html',form=form, action_error_msg = action_error_msg, succeed = succeed) return render_template('upload.html',form=form, action_error_msg = None, succeed = False)
def setting(): from app.forms import SetForm form = SetForm() if form.validate_on_submit(): servers = models.ServerIP.query.all() for server in servers: db.session.delete(server) db.session.commit() serverip = form.ip.data u = models.ServerIP(serverip = serverip) db.session.add(u) db.session.commit() return render_template('setting.html',form=form, succeed = True) return render_template('setting.html',form=form)