Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to pre populate field flask wtforms

form.populate_obj(user)
user.site = form.website.data
db.session.commit()
Comment

how to pre populate field flask wtforms

@decorator_authorized_user  # This decorator should make sure the user is authorized, like @login_required from flask-login
def editprofile(nickname = None):
    # Prepare the form and user
    form = EditProfile()
    form_action = url_for('profile.editprofile')
    my_user = Users.get(...)  # get your user object or whatever you need
    if request.method == 'GET':
        form.username.data = my_user.username
        form.email.data = my_user.email
        # and on
    if form.validate_on_submit():
        # This section needs to be reworked.
        # You'll want to take the user object and set the appropriate attributes
        # to the appropriate values from the form.
        if form.username.data == nickname: 
            query = EditProfile(form.username.data,
                                form.email.data,
                                form.about.data,
                                form.website.data,
                                )
            print query #debug
            db.session.add(query)
            db.session.commit()
            flash('User Updated')
            print "added"
            return(url_for('profile.editprofile'))
    return render_template('profile/add.html', form=form,
                           form_action=form_action, title="Update Profile")
Comment

PREVIOUS NEXT
Code Example
Python :: scroll to top selenium python 
Python :: symmetric_difference() Function of sets in python 
Python :: ipython play audio 
Python :: how to play audio in python using pygame 
Python :: como poner estado a un bot en discord 
Python :: df iloc 
Python :: cv2.imshow not working in vscode 
Python :: import excel 
Python :: pandas index append value 
Python :: Django - Knox auth setup 
Python :: python running mean pandas 
Python :: how to leave a function python 
Python :: pygame template 
Python :: python format new 
Python :: pandas series map 
Python :: how to append a tuple to a list 
Python :: python different types of loops 
Python :: Python script from c++ 
Python :: python strftime cheat sheet 
Python :: display pil image on kivy canvas 
Python :: how to print a value of a key in nested dictionary python 
Python :: how to find duplicates in csv file using python 
Python :: python binary float 
Python :: python single vs double quotes 
Python :: create a file in a specific directory 
Python :: django add queury parameters to reverse 
Python :: python web app 
Python :: filter in python 
Python :: 2nd to last index python 
Python :: use argparse to call function and use argument in function 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =