简体   繁体   English

Google App Engine - Python和bigtable渲染

[英]Google App Engine - Python and render from bigtable

I there: 在这里:

I am experimenting with GAE and i wish to create a CMS using plain python (not Django or another framework). 我正在尝试使用GAE,我希望使用普通的python(不是Django或其他框架)创建CMS。 And my problem is that GAE does not allow to save files, so i can save a user-created template in a folder. 我的问题是GAE不允许保存文件,因此我可以将用户创建的模板保存在文件夹中。

When you want to render a file, you use the next command: 如果要渲染文件,请使用下一个命令:

    tmpl = os.path.join(os.path.dirname(__file__), 'templates/mypage.html')
    self.response.out.write(render(tmpl, context))

Is there are a way to render directly from a registry from BigTable or from a variable instead of a file? 有没有办法从BigTable直接从注册表或从变量而不是文件呈现? (without using Django). (不使用Django)。

For a start, if you're using template.render , you are using a framework: the minimal "webapp" framework included with GAE. 首先,如果您正在使用template.render ,那么您正在使用一个框架:GAE附带的最小“webapp”框架。 And, of course, the template module itself is a thin wrapper around Django's template library. 当然, template模块本身是Django模板库的一个薄包装器。 However, the wrapper - which takes care of a few incompatibilities between Django and webapp - doesn't expose a method for rendering directly from a string. 但是,包装器 - 它处理Django和webapp之间的一些不兼容性 - 不会公开直接从字符串呈现的方法。

It does allow access to the basic django Template class, which can be used to instantiate a template directly from a template string: 允许访问基本的Django的Template类,它可以被用来直接从一个模板字符串实例化一个模板:

tmpl = template.Template(template_string)
tmpl.render(template.Context(context))

This might work - or it might not, because of those incompatibilities. 这可能有效 - 或者可能不会,因为这些不兼容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM