如果您的文本文件总是小于 1 兆,并且您不打算扩展到大量用户,那么设置一个系统将您的文本文件作为 TextProperty 发布到实体中将非常容易。如果您是 GAE 的新手,那么运行它可能需要不到 1 小时。我这样做是为了加快我的 HTML 工作的测试速度(比部署静态文件快一英里)。以下是一些非常简单的代码摘录作为示例。(如果我在修改它以简化/匿名化时搞砸了,我深表歉意。) HTH -stevep
#client side python...
import time
import urllib
import httplib
def processUpdate(filename):
f = open(filename, 'rb')
parts = filename.split('/')
name = parts[len(parts)-1]
print name
html = f.read()
f.close()
htmlToLoad = urllib.quote(html)
params = urllib.urlencode({'key':'your_arbitrary_password_here(or use admin account)',
'name':name,
'htmlToLoad':htmlToLoad,
})
headers = {'Content-type': 'application/x-www-form-urlencoded', 'Accept': 'text/plain'}
#conn = httplib.HTTPConnection('your_localhost_here')
conn = httplib.HTTPConnection('your_app_id_here')
conn.request('POST', '/your_on-line_handler_url_stub_here', params, headers)
response = conn.getresponse()
print '%s, %s, %s' % (filename, response.status, response.reason)
def main():
startTime = time.time()
print '----------Start Process----------\n'
processUpdate('your_full_file01_path_here')
processUpdate('your_full_file02_path_here')
processUpdate('your_full_file03_path_here')
print '\n----------End Process----------', time.time() - startTime
if __name__ == '__main__':
main()
# GAE Kind
class Html_Source(db.Model):
html = db.TextProperty(required=True, indexed=False)
dateM = db.DateTimeProperty(required=True, indexed=False, auto_now=True)
v = db.IntegerProperty(required=False, indexed=False, default=1)
#GAE handler classes
EVENTUAL = db.create_config(read_policy=db.EVENTUAL_CONSISTENCY)
class load_test(webapp2.RequestHandler):
def post(self):
self.response.clear()
if (self.request.get('key') != 'your_arbitrary_password_here(or use admin account)'):
logging.info("----------------------------------bad key")
return
name = self.request.get('name')
rec = Html_Source(
key_name = name,
html = urllib.unquote(self.request.get('htmlToLoad')),
)
rec.put()
self.response.out.write('OK=' + name)
class get_test(webapp2.RequestHandler):
def get(self):
urlList = self.request.url.split('/')
name = urlList[len(urlList) - 1]
extension = name.split('.')
type = '' if len(extension) < 2 else extension[1]
typeM = None
if type == 'js': typeM = 'application/javascript'
if type == 'css': typeM = 'text/css'
if type == 'html': typeM = 'text/html'
self.response.out.clear()
if typeM: self.response.headers["Content-Type"] = typeM
logging.info('%s-----name, %s-----typeM' % (name, typeM))
htmlRec = Html_Source.get_by_key_name(name, config=EVENTUAL)
if htmlRec is None:
self.response.out.write('<p>invalid:%s</p>' % (name))
return
self.response.out.write(htmlRec.html)