Advertisement
Guest User

Untitled

a guest
Feb 25th, 2011
1,469
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.75 KB | None | 0 0
  1. ##the form definition-------------
  2. class TheBlogForm(wtf.Form):
  3.     title=wtf.TextField('Blog Title',validators=[validators.Required()])
  4.     blogdata=wtf.TextAreaField('The Blog',validators=[validators.Required()],)
  5.     published=wtf.BooleanField('Published')
  6.  
  7. ##the view function ----------------------------
  8. --------------------------------------------
  9. @theblog.route('/editblog/<blogtitle>',methods=['GET','POST'])
  10. @admin_required
  11. def editblog(blogtitle):
  12.     """THIS does the editing of the blog.. the problem is the textarea field has to display the value ..which it is not doing"""
  13.     blog=db.Query(TheBlog).filter('title =',blogtitle).get()
  14.     form=TheBlogForm()
  15.     if form.validate_on_submit():
  16.         blog.title=form.title.data
  17.         blog.blogdata=form.blogdata.data
  18.         blog.published=form.published.data
  19.         blog.put()
  20.         return redirect(url_for('admin'))
  21.     else:
  22.         g.title=blog.title
  23.         g.blogdata=blog.blogdata
  24.     return render_template('editblog.html',form=form)
  25.  
  26.  
  27.  
  28. ---------the html of the form template
  29.  
  30.                  <h1>Edit Blog</h1>
  31.                     <form action="" method="post" accept-charset="utf-8" enctype="multipart/form-data">
  32.                         {{ form.csrf_token }}
  33.                     <ol>
  34.                          <li>{{form.title.label}}</li>
  35.                          <li>{{form.title(value=g.title)}}</li>
  36.                          <li>{{form.blogdata.label}}</li>
  37.                          <li>{{form.blogdata(content=g.blogdata)}}</li>
  38.                          <li>{{form.published.label}}</li>
  39.                          <li>{{form.published()}}</li>
  40.                     </ol>
  41.                     <input type="submit" name="submit" value="submit"/>
  42.                     </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement