Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##the form definition-------------
- class TheBlogForm(wtf.Form):
- title=wtf.TextField('Blog Title',validators=[validators.Required()])
- blogdata=wtf.TextAreaField('The Blog',validators=[validators.Required()],)
- published=wtf.BooleanField('Published')
- ##the view function ----------------------------
- --------------------------------------------
- @theblog.route('/editblog/<blogtitle>',methods=['GET','POST'])
- @admin_required
- def editblog(blogtitle):
- """THIS does the editing of the blog.. the problem is the textarea field has to display the value ..which it is not doing"""
- blog=db.Query(TheBlog).filter('title =',blogtitle).get()
- form=TheBlogForm()
- if form.validate_on_submit():
- blog.title=form.title.data
- blog.blogdata=form.blogdata.data
- blog.published=form.published.data
- blog.put()
- return redirect(url_for('admin'))
- else:
- g.title=blog.title
- g.blogdata=blog.blogdata
- return render_template('editblog.html',form=form)
- ---------the html of the form template
- <h1>Edit Blog</h1>
- <form action="" method="post" accept-charset="utf-8" enctype="multipart/form-data">
- {{ form.csrf_token }}
- <ol>
- <li>{{form.title.label}}</li>
- <li>{{form.title(value=g.title)}}</li>
- <li>{{form.blogdata.label}}</li>
- <li>{{form.blogdata(content=g.blogdata)}}</li>
- <li>{{form.published.label}}</li>
- <li>{{form.published()}}</li>
- </ol>
- <input type="submit" name="submit" value="submit"/>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement