简体   繁体   中英

How to make almost static site in Pyramid?

I'm switching to Pyramid from Apache/PHP/Smarty/Dreamweaver scheme.

I mean the situation of having static site in Apache with menu realized via Dreamweaver template or other static tools. And then if I wanted to put some dynamic content in html I could make the following:

  1. Put smarty templates in html.
  2. Create php behind html with same name. Php takes html as template.
  3. Change links from html to php.

And that was all. This scheme is convenient because the site is viewable in browser and editable in Dreamweaver.

How can I reproduce this scheme in Pyramid? There are separate dirs for templates and static content. Plus all this myapp:static modifiers in hrefs. Where to look up?

Thank you for your advices.

  1. There is no smarty port for Python. So you would have to start using another template syntax, such as mako or chameleon
  2. To do this, you would setup your view_config to respond to the url, end tell it to use the corresponding template.
  3. If you want to do this, you would simple change your code. But this is not necessary, pyramid will process your requests, whether the url contains .html, .php, .python, /, or whatever.

You could still edit the templates in Dreamweaver I guess.

Only really static pages would be linked using static_url . If it is html that you mean to make into a template, it might be easiest to just start of with a template right away, without any dynamic content in it.

This is from the URL dispatch tutorial :

# in views.py
@view_config(route_name='view_page', renderer='templates/view.pt')
    def view_page(request): 
        return {}

# in __init__.py
config.add_route('view_page', 'mypage.html')

You can build a small web application which uses traversal to serve html documents from a directory. Here's more explanations about how traversal works .

Then you can programmatically render those documents as Chameleon templates, using PageTemplateFile for example. This would allow you to include, say, common header/footer/navigation into every page.

This would mean that every page in your site will be in fact dynamic, so that would incur a small performance penalty for every page regardless of whether it has dynamic content or not, but you should not be concerned with this unless you're building the next Facebook. :) However, this approach would allow you to have a plain html document corresponding to every page in your website which you'll be able to edit using Dreamweaver or any other editor.

This is somewhat a different answer than ohters but here is a completely different flow.

Write all your pages in html. Everything!!! and then use something like angularjs or knockoutjs to add dynamic content. Pyramid will serve dynamic content requested using ajax.

You can then map everything to you html templates... edit those templates wherever you want since they are simply html files.

The downside is that making it work altogether isn't that simple at first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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