python - WTForm: Update user information without adding the blank fields? -


i trying add update profile information section website. , whenever update information deletes previous information when field left blank, , replaces none value. not want when people update profiles.

this form:

class editform(form):     displayname = stringfield('displayname', validators=[optional(),length(min=3, max=25)], filters = [lambda x: x or none])     status = stringfield('status', validators=[optional(),length(min=1, max=64)], filters = [lambda x: x or none])     gender = stringfield('gender', validators=[optional(),length(min=3, max=25)], filters = [lambda x: x or none])     age = integerfield('age', validators=[optional(),numberrange(min=1, max=2)], filters = [lambda x: x or none])     pref = textareafield('pref', validators = [optional()], filters = [lambda x: x or none])     = textareafield('pref', validators = [optional()], filters = [lambda x: x or none])     img =stringfield('image url', validators = [optional(), length(max = 100)], filters = [lambda x: x or none]) 

as can see, have optional added , filters.

for page itself, have following:

@app.route("/settings" , methods=['get','post']) @login_required def settings():     user=g.user     error=none     userinfo = usersettings.query.filter_by(username=user.username).first()     formo = editform(request.form)     if formo.validate_on_submit():         userinfo.displayname = formo.displayname.data         userinfo.status=formo.status.data         userinfo.gender=formo.gender.data         userinfo.age=formo.age.data         userinfo.pref=formo.pref.data         userinfo.about=formo.about.data         userinfo.img=formo.img.data         db.session.commit()         return redirect(url_for('dash'))     return render_template("settings.html", error=error, formo=formo, userinfo=userinfo, user=user) 

is there different way go this?


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo