Can I write an output buffer/filter with web.py?
-
I'm trying to migrate my personal website from PHP to Python (partly to become more fluent in Python). My website is bilingual but I have a very specific case where I do not want to go through the pain of a full-blown i18n interface. The way I have it set up now, I can do things like the following directly in my .php files: {|en:Test|zh:測試|} <img src="banner_{|en:en|zh:zh|}.jpg"> <style type="text/css"> body {font-size:{|en:10|zh:12|}px}; </style> {|en:This content to be seen by English users only|zh:|} My PHP templating script, which gets included on every page, uses an output buffer (i.e. ob_start()) to take care of selecting the correct language out of the each of the strings. In other words, my translations are embedded directly inside the content (because this is a 1-user personal website, I want to be able to update content without wasting time going through a separate interface, and translations are done by me; it is not a full-blown webapp). Can such output buffers be done with http://web.py or any similar Python framework without going through a full-blown i18 system (which is a pain for a personal, largely-static website with only 2 languages)?
-
Answer:
Most python templating engines support something akin to this. Some are based off domain specific languages, others based off of filter functions. I would recommend you use the excellent Jinja2 template engine to do exactly this. It comes stock in the Flask framework, but can easily be used along with web py. http://jinja.pocoo.org/docs/ A thread on custom filters with http://web.py https://groups.google.com/forum/?fromgroups=#!topic/webpy/yvn6TeL1NWA
Mark Grey at Quora Visit the source
Related Q & A:
- how can I write this shell script in python?Best solution by Stack Overflow
- How can I write a good reference letter?Best solution by dailywritingtips.com
- How can I write an interview essay?Best solution by Yahoo! Answers
- How can I write to oprah winfrey?Best solution by wikihow.com
- How can I write my college essay?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.