Question

The website I am overhauling is currently using python 2.3.7, and is managed using the Google App Engine it has to be updated to 2.7 and because of the new version features, the template section was depreciated. what are the nessesary changes that need to be made this? FYI, I'm a highschool student doing this for a chatroom website. When i rewrite the changes for the app.yaml, change the code inside the .py (then i retitle the file to .app), it throws this traceback error. help?

File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 196, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/base/python27_runtime/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 255, in _LoadHandler
    handler = __import__(path[0])
ImportError: No module named devchat

my imports are

import cgi
import os
import urllib
import logging

from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.ext.webapp import template
from google.appengine.api import memcache

the section of the code concerning templates is here

class BaseRequestHandler(webapp.RequestHandler):

  def generate(self, template_name, template_values={}): 
    # We check if there is a current user and generate a login or logout URL
    user = users.get_current_user()

    if user:
      log_in_out_url = users.create_logout_url('/')
    else:
      log_in_out_url = users.create_login_url(self.request.path)

    # We'll display the user name if available and the URL on all pages
    values = {'user': user, 'log_in_out_url': log_in_out_url}
    values.update(template_values)

    # Construct the path to the template
    directory = os.path.dirname(__file__)
    path = os.path.join(directory, 'templates', template_name)

    # Respond to the request by rendering the template
    self.response.out.write(template.render(path, values, debug=_DEBUG))

class MainRequestHandler(BaseRequestHandler):
  def get(self):
    if users.get_current_user():
      url = users.create_logout_url(self.request.uri)
      url_linktext = 'Logout'
    else:
      url = users.create_login_url(self.request.uri)
      url_linktext = 'Login'

    template_values = {
      'url': url,
      'url_linktext': url_linktext,
      }

    self.generate('index.html', template_values);

class ChatsRequestHandler(BaseRequestHandler):
  def renderChats(self):
    greetings_query = Greeting.all().order('date')
    greetings = greetings_query.fetch(1000)

    template_values = {
      'greetings': greetings,
    }
    return self.generate('chats.html', template_values)

  def getChats(self, useCache=True):
    if useCache is False:
      greetings = self.renderChats()
      if not memcache.set("chat", greetings, 10):
        logging.error("Memcache set failed:")
      return greetings

    greetings = memcache.get("chats")
    if greetings is not None:
      return greetings
    else:
      greetings = self.renderChats()
      if not memcache.set("chat", greetings, 10):
        logging.error("Memcache set failed:")
      return greetings

  def get(self):
    self.getChats()

  def post(self):
    greeting = Greeting()

    if users.get_current_user():
      greeting.author = users.get_current_user()

    greeting.content = self.request.get('content')
    greeting.put()

    self.getChats(False)`
Was it helpful?

Solution

Here is a very good video, which explains how you have to update your application: https://developers.google.com/events/io/sessions/gooio2012/300/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top