开发者

Google App Engine - Python and render from bigtable

开发者 https://www.devze.com 2023-03-27 00:19 出处:网络
I there: I am experimenting with GAE and i wish to create a CMS using plain python (not Django or another framework).And my problem is that GAE does not allow to save files, so i can save a user-crea

I there:

I am experimenting with GAE and i wish to create a CMS using plain python (not Django or another framework). And my problem is that GAE does not allow to save files, so i can save a user-created template in a folder.

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 开发者_Go百科way to render directly from a registry from BigTable or from a variable instead of a file? (without using Django).


For a start, if you're using template.render, you are using a framework: the minimal "webapp" framework included with GAE. And, of course, the template module itself is a thin wrapper around Django's template library. 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.

It does allow access to the basic django Template class, which can be used to instantiate a template directly from a template string:

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

This might work - or it might not, because of those incompatibilities.

0

精彩评论

暂无评论...
验证码 换一张
取 消