2
\$\begingroup\$

Please review this simple code. When I review it I decide to rewrite so that it doesn't write to a template, but instead directly to output since the whole HTML is fetched from the data layer. I used the tool appengine_admin to get editable HTML for simple html capabilities to an appspot project:

    class Page(db.Model):
      html = db.TextProperty(required=True)

    class AdminPage(appengine_admin.ModelAdmin):

        model = Page
        listFields = (
            'html',
            )
        editFields = (
            'html',
            )



  application = webapp.WSGIApplication([  ('/page/([0-9]+)', PageHandler), ])

  class PageHandler(BaseHandler):
      def get(self, file_id):
        page = Page.get_by_id(long(file_id))
        if not page:
          self.error(404)
          return
        self.render_template(file_id+'.html', {
            'body': page.body,
        })

My 2 to-dos:

  1. change variable file_id to page_id
  2. change writing to direct output instead of template
\$\endgroup\$
3
\$\begingroup\$
  application = webapp.WSGIApplication([  ('/page/([0-9]+)', PageHandler), ])

I'd put the list of urls as a global constant, I think that would make it easier to read.

  class PageHandler(BaseHandler):
      def get(self, file_id):
        page = Page.get_by_id(long(file_id))
        if not page:

If you are checking against None here, I'd use if page is None:

  self.error(404)
  return

I'd use else instead of returning here

self.render_template(file_id+'.html', {
    'body': page.body,
})
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.