# [START imports]
import os
import webapp2
import jinja2

from google.appengine.ext import db
# [END imports]


# [START template mgmt & BaseHandler]
template_dir = os.path.join(os.path.dirname(__file__), 'templates')
jinja_env = jinja2.Environment(loader=jinja2.FileSystemLoader(template_dir),
                               autoescape=True)


class BaseHandler(webapp2.RequestHandler):
    def write(self, *a, **kw):
        self.response.out.write(*a, **kw)

    def render_str(self, template, **params):
        t = jinja_env.get_template(template)
        return t.render(params)

    def render(self, template, **kw):
        self.write(self.render_str(template, **kw))
# [END template mgmt & BaseHandler]


# [START Main Page]
class MainPage(BaseHandler):
    def render_main(self):
        self.render("main.html")

    def get(self):
        self.render_main()
# [END Main Page]

# [START New Post]
class NewPost(BaseHandler):
    def render_newpost(self):
        self.render("newpost.html")

    def get(self):
        self.render_newpost()

# [END New Post]


# [START app]
app = webapp2.WSGIApplication([
    ('/', MainPage),
    ('/newpost', NewPost)
], debug=True)
# [END app]

@@ -882,16 +882,17 @@
  Page%5D%0A%0A
+%0A
 # %5BSTART
@@ -953,24 +953,57 @@
 newpost(self
+, title=%22%22, blogPost=%22%22, error=%22%22
 ):%0A        s
@@ -1031,76 +1031,594 @@
 tml%22
-)%0A%0A    def get(self):%0A        self.render_newpost()%0A%0A# %5BEND New Post
+, title=title,%0A                    blogPost=blogPost, error=error)%0A%0A    def get(self):%0A        self.render_newpost()%0A%0A    def post(self):%0A        title = self.request.get(%22title%22)%0A        blogPost = self.request.get(%22blogPost%22)%0A%0A        if title and blogPost:%0A            self.redirect(%22/thanks%22)%0A        else:%0A            error = %22Please submit both a title and a blogpost!%22%0A            self.render_newpost(title, blogPost, error)%0A# %5BEND New Post%5D%0A%0A%0A# %5BSTART Thanks page - temp%5D%0Aclass Thanks(BaseHandler):%0A    def get(self):%0A        self.render(%22thanks.html%22)%0A# %5BEND Thanks page - temp
 %5D%0A%0A%0A
@@ -1709,16 +1709,42 @@
 NewPost)
+,%0A    ('/thanks', Thanks),
 %0A%5D, debu

Update NewPost class for error handling