Sunday, July 30, 2006

Bruce Eckel 看 TurboGears

我想, 這是第一次有了個網站框架將它的功能做得這麼容易明白.
I think this is the first time that a web framework's functionality has been so obvious
-- Bruce Eckel

原文: The Web Frameworks Jam and Turbogears

誰是 Bruce Eckel ?

Bruce Eckel 是 Thinking in Java, Thinking in C++ 系列書的作者, 作品享有很高的聲譽.

Friday, July 28, 2006

IPv6-IPv4 TCP Relay & PortProxy

在看 ブロードバンドルータ(CG-BARPRO6)によるOCN IPv6接続 這篇文章時,
發現回覆中提到很可惜沒支援 "v6-v4 TCP Relay" 這功能.

IPv6-IPv4 TCP Relay 到底是什麼呢?

上網查了一查, 原來就是一種 BIS(Bump In Stack) 的應用, 讓 IPv4 Only的程式可以透過 Port Mapping 來存取 IPv6 網路.

例如回覆中提到一台僅支援 IPv4 的網路電視機器, 因為區網內使用私有地址的關係, 需要在外部建一台 Virtual Server 才能在各地存取網路電視這資源.
如果 Router 能支援 "IPv6-IPv4 TCP Relay", 我們就能在外部使用 IPv6 位址存取網路電視了!

想起來就很讚, 做起來.......:-D

介面 Portproxy 的 Netsh 命令

Saturday, July 22, 2006

TurboGears 中使用 Django 模板

利用 TurboDjango Template Plugin, 可以在 TurboGears, Buffet, 或 CherryPy 裡如此這般調用 Django 模板:

在 裡
@expose(template = "django:dem.templates.djpage")
def page(self):
return dict(name="TurboGears")


用 "template " 參數指定樣板時加一個"django:"前綴,
或是在設定檔app.cfg中將預設的tg.defaultview = "kid" 改成
tg.defaultview = "django" 就可以在全站使用 django 模板.

djpage 是模板名稱, return dict

在 djpage.html 裡

[h1]Hello, {{name}}[/h1]


djpage 是模板名稱, html是檔名

網頁 http://localhost:8080/page 的輸出結果是


Hello, {{name}}


Wednesday, July 12, 2006

Assimilate Django Template to TurboGears

Lots of people use Django template for Pyhton Web Framework(As Django project shares).

And if we want to make people feel comfortable to try TurboGears (and then migrate to tg hopefully), first thing we can do is making django template system available on TurboGears.

Its easy because many template plugins (and their source codes) are available for TurboGears, I use a couple hours to read the template plugins doc and make the TurboDjango template plugin.

You can try the django template in minutes. Here is the step by step guide:

Install By SetupTools

$ easy_install TurboDjango

How to Make it just Work?

Step 1. Quickstart

Use tg-admin tool to create a project

$ tg-admin quickstart tgdj

The project name is "tgdj"

Step 2. Edit Controller

Edit tgdj/tgdj/, add following method in "Root" class.
@expose(template = "django:tgdj.templates.djpage")
def page(self):
return dict(name="TurboGears")

"djpage" is django template name

Step 3. Edit Template

Edit tgdj/tgdj/templates/djpage.html

[h1]Hello, {{name}}[/h1]

The template has "html" file suffix

Step 4. Check Result

In tgdj, start develop server by typing

$ start-tgdj

Then surf http://localhost:8080/page, you'll see

Hello, TurboGears

The Release is available here.

To Django Users: You can migrate your database with SQLAlchemy's SqlSoup

Tuesday, July 11, 2006

Step-by-Step Guide for Setting Up IPv6 in a Test Lab

Microsoft's Step-by-Step Guide for Setting Up IPv6 in a Test Lab

Saturday, July 08, 2006

TurboGears with SqlSoup


Have an exist database and want migrate to TurboGears?
Or you've been using TurboGears SQLObject model and want to migrate to SQLAlchemy?


TurboGears newly support SQLAlchemy 0.2 module(>0.9a6), it provide a slick solution: SqlSoup !

What SqlSoup does?

SqlSoup inspects your database and reflects its contents to class, no model definitions are necessary!

What does that mean?

It means you only need to specify a uri for database,
and call SqlSoup to do the rest.

What's the Benifits?

SqlSoup maps database tables to classes automatically. I'm not sure how efficient it is, but at least you can use SqlSoup by following ways:
  • To use existing Database design tools to design my database
  • To use SqlSoup in design phase, and code to SQLAlchemy class when the databse is settled down.
  • To painless migrate SQLObject generated database to SQLAlchemy
Test Code

Try the test code, it is thin.


1 from sqlalchemy.ext.sqlsoup import SqlSoup

2 uri = "sqlite://%(current_dir_uri)s/devdata.sqlite"
3 soup = SqlSoup(uri)


line 1 import SqlSoup from sqlalchemy module,

line 2 specify the uri link to the database (I believe it can be improved)

line 3 the real code calling SqlSoup connect to uri

line 4 and line 5 shows I call the table "poll" from database

if you can't execute is , maybe you should install sqlalchemy first
$ easy_install sqlalchemy

or try the TurboGears way:

1 from turbogears import config
2 from sqlalchemy.ext.sqlsoup import SqlSoup

3 uri = config.get('sqlalchemy.dburi')
4 soup = SqlSoup(uri)

All you need to do is specify the dburi for sqlsoup.

Let's test what we got

>>> poll =
>>> print poll


That's all you need in TurboGears.
To get further usage , you can refer to Introducing SqlSoup

ps: Actually TurboGears has done nothing particularly to support SqlSoup, I just use it as other modules.

Wednesday, July 05, 2006

Eclipse Configuration for TurboGears

Continue to my previous article, here is a configuration using eclipse external tools to start web server without open

Here is a list of the current functionality:

External Tools:
  • Start Server
  • Start Toolbox
  • Auto Completion

Configure Eclipse to Launch developer server
  • Select Run -> External Tools -> External Tools
  • Select "Program" from the configuration tree
  • Select New to create a new program
  • Enter “Start Server” as the name
  • Enter C:\Python24\pythonw.exe for the Location
  • For the Working Directory, use
  • Enter start-${project_name}.py for the Arguments
  • Select the refresh tab and check Refresh Resources Upon Completion
  • Select the Common tab
    • Find the section for Display in Favorites Menu
    • Check External Tools option
  • Select Apply
Configure Eclipse to Launch ToolBox
  • Select Run -> External Tools -> External Tools
  • Select "Program" from the configuration tree
  • Select New to create a new program
  • Enter “Start ToolBox” as the name
  • Enter C:\Python24\Scripts\tg-admin.exe for the Location
  • For the Working Directory, use
  • Enter toolbox for the Arguments
  • Select the Common tab
    • Find the section for Display in Favorites Menu
    • Check External Tools option
  • Select Apply

  • Select your project in Navigator panel
  • Select Properties on Right click menu.
  • Select pyDev - PYTHONPATH
  • Select Add source folder to add project path in Project Source Folder.
    it will bring project code-completion and code-analysis.
  • Select Add source folder to add turbogears path in External Source Folder.
    it will bring turbogears code-completion
PS: I get idea from the rails article, but for mine, you'd have eclipse & pydev installed, I recommand you try EasyEclipse for Python.

Sunday, July 02, 2006

EasyEclipse for Python and TurboGears

EasyEclipse for python

People who are used to Microsoft VisualStudio or Java IDE usually criticize that python has no good IDE to cooperate with,

I think pydev is one of good python IDE, which is based on eclipse platform.
But since you try to install it, it's pretty annoying to set the eclipse and pydev run properly.

Now EasyEclipse project provide an easy install pack of Eclipse for python, it contains:
  • eclipse platform itself,
  • pydev(eclipse python support),
  • Subclipse(eclipse SVN GUI),
  • and several useful plugins installed by default.
It really ease the installation and configuration of Eclipse for python.

Pydev with Turbogears

Besides that, Pydev developer recently wrote an article for Configuring Pydev to work with Turbogears

It sounds like a right time to try for pydev + TurboGears.

So I searched and installed the Eclipse for python and EasyEclipse Web tools editors for eclipse HTML/CSS editor and an Internal Web Browser.

The result? It's not much too say.... pretty good:D

Start Up

First create a pydev project, it will assign a workspace for the project.
Open the console, change path to the workspace folder.
Use tg-admin tool to create a TurboGears projects named "projectname" within the pydev project workspace folder.

Now the project folder will shown on eclipse Navigator panel. (you may need use right click menu-> refresh)
click the
tap F9, then the web server will run.

You can use the "Open Web Browser" icon which is near with the search icon to open the internal Web Browser. Type http://localhost:8080 to see the welcome page :)

Sounds good?


Here are a little configuration tips you may intrested...

Assign the python interpretor

1. open window/preference,
select pydev/interpreter-python,
click top right "Add" button to select the python.exe path (windows default is C:\python24\pythonw.exe).
The proper library and key words will automatically load for you to use.

Template Association

2. select General/Editors/File Association,
click top right "new" button to add "*.kid" file style for kid template.
Press the second "Add" button to assign the associate editors to HTML Editor(default) and Internal Web Browser.

I also found a WYSIWYG HTML editor
EasyEclipse eZingBuilder, but I can't get the kid page present correctly now.

more tips are welcome

EasyEclipse for Python

習慣用微軟 VisualStudio 或用 Java 的人用了 python 語言,
通常會挑剔 python 語言沒什麼好用的 IDE 來搭配.

現在 EasyEclipse 有提供包好的 eclipse + pydev(eclipse
平台上的 python 語言支援-) + Subclipse
(eclipse平台上的圖形化 SVN 版本控制工具)

簡化了 eclipse 平台安裝設定上的繁瑣, 拿來做 python