gpt4 book ai didi

python - 网站需要在 python 中更新

转载 作者:太空宇宙 更新时间:2023-11-04 06:34:33 25 4
gpt4 key购买 nike

我正在大修的网站目前使用的是 python 2.3.7,并且使用 Google App Engine 进行管理,它必须更新到 2.7,并且由于新版本的功能,模板部分已贬值。需要对此进行哪些必要的更改?仅供引用,我是一名为聊天室网站做这件事的高中生。当我重写 app.yaml 的更改时,更改 .py 中的代码(然后我将文件重命名为 .app),它会抛出此回溯错误。帮助?

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)`

最佳答案

这是一个非常好的视频,解释了如何更新您的应用程序:https://developers.google.com/events/io/sessions/gooio2012/300/

关于python - 网站需要在 python 中更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13115138/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com