Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing WTForms' populate_obj( ) method with Flask micro framework
    text
    copied!<p>I have a template which allows the user to edit their user information.</p> <pre><code>&lt;form method="post"&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;Username:&lt;/td&gt; &lt;td&gt;{{user['username']}}&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;New Password:&lt;/td&gt; &lt;td&gt; &lt;input type="password" name="password"&gt;&lt;/td&gt; &lt;td&gt;{% if form.password.errors %} {{form.password.errors}} {% endif %}&lt;td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;Re-enter Password:&lt;/td&gt; &lt;td&gt; &lt;input type="password" name="confirm_password"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;input type='hidden' name='username' value="{{user['username']}}"&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="submit" value="Submit"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/form&gt; </code></pre> <p>I also have a view function for handling such edits by the user. The database I am currently using is <a href="http://en.wikipedia.org/wiki/MongoDB" rel="nofollow">MongoDB</a> with the <a href="http://pypi.python.org/pypi/mongokit" rel="nofollow">MongoKit</a> module. I have only been able to do up to this so far in the view function, yet with no luck.</p> <pre><code>def edit(): username = request.args.get('user') user = User.find_one({'username':username}) # Is this a correct way of doing it? form = UserForm(**what should be placed here?**, obj=user) if request.method == 'POST' and form.validate(): form.populate_obj(user) user.save() return 'updated' return render_template('edituser.html', form=form, user=user) </code></pre> <p>I am going through <a href="http://wtforms.simplecodes.com/docs/0.6.1/forms.html#wtforms.form.Form.populate_obj" rel="nofollow">populate_obj(obj)</a> for this purpose. I couldn't find much help in this matter. What should I do in order to get <code>populate_obj()</code> working?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload