2
我大修的網站目前使用python 2.3.7,並且使用Google App Engine進行管理,它必須更新到2.7版本,並且由於新版本功能,模板部分已折舊。需要做出什麼修改呢?僅供參考,我是一名高中生在聊天室網站上做這件事。當我重寫app.yaml的更改時,更改.py內的代碼(然後將文件重新命名爲.app),它會引發此跟蹤錯誤。幫幫我?網站需要更新python
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
我進口
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
有關模板的代碼段是在這裏
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)`
你有什麼問題?有錯誤嗎?什麼webapp庫/框架正在使用(什麼是導入)? – jozzas
我更新了問題 – user1781766
你說你把文件重命名爲'.app'?你實際上不需要這麼做 - 你看到的'main.app'例子可以像'main.py'中的'app'變量那樣讀取。所以你的第一步是將文件重命名爲'devchat.py'(或任何原始文件:))。然後你想確保你的'devchat.py'中有一行代碼是'app = webapp.WSGIApplication([('/',MainRequestHanlder)])'',這就是你將處理器的佈局。 – RocketDonkey