开发者

beginner pylons / mako templating questions

开发者 https://www.devze.com 2023-01-29 16:04 出处:网络
I\'ve been reading mako / pylons documentation and am having trouble finding good examples / discussion of integrating multiple applications into a single page, so for example, if i had a blog applica

I've been reading mako / pylons documentation and am having trouble finding good examples / discussion of integrating multiple applications into a single page, so for example, if i had a blog application and an application which just selects a random quotation from a database of awesome quotations. (the example is trivial, just for exposition)

So I want to make a single page which displays both applications, I'm not sure how to go about writing the templates, i've seen next.body(), do I need to call the controller from the application in a template?

How could I do this o开发者_运维问答n the fly?

Can I just make a model describing the page, and have each application it wants to call as objets in the attributes of the model? I'm just spitballing here, hoping for a pointer to an example / tutorial i can look over.

Thanks for any advice.


In Django, "applications" are components you develop or choose, then customize, mix and match together to get your final website.

In Pylons, "application" refers to the whole thing you're creating--controllers, models, templates, middlewares, any helper modules, documentation etc. A Pylons application is a bunch of code that can be served as-is by Paster, Apache/mod_wsgi or any other WSGI-supporting web server.

In Pylons, to get, for example, blog posts and random quotations in single page, you'd:

  • Create separate models for representing and manipulating blog entries and quotes, like myapp.model.Post, myapp.model.Quotation.
  • Create a controller action that queries models to get X blog posts and a single quotation, put them in data object that will be passed to template.
  • Create a template that displays both blog posts and quotation on single page. This template can, of course, inherit from some base template or include template fragments, so you don't have to copy-paste common HTML code across many templates.

Hope this helps!

0

精彩评论

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