Back to Python#Web_Applications

See Also Jinja2Nginx

Web.py

Web.py是一个针对Python的web框架,简单而又强大。Web.py中没有向导或者模板网站,必须从头构建。它不提供管理工具。Web.py是Aaron Swartz的作品,是他Reddit.com工作时开发出来的。

1. Get Started

http://webpy.org/docs/0.3/tutorial: 30分钟不到的入门文档,然后就可以coding了。

➜  web.py virtualenv env
➜  web.py source env/bin/active
(env) ➜  web.py pip install web.py
(env) ➜  web.py pip install jinja2

1.1. Serving Static Files

http://webpy.org/cookbook/staticfiles

Create static folder

1.2. How to use forms

Form Library/api docs: web.form

http://webpy.org/cookbook/forms

1.2.1. Checkbox

Checkbox以默认方式赋值的时候无法获得状态,需要这样写:

web.form.Checkbox('Reversed', description=u'是否倒序', value=True), 

Dropdown以默认方式赋值无法多选,需要这样写:

web.form.Dropdown('Columns', ['All', 'C16', 'C12'], description=u'显示字段', multiple=True),

1.3. Use Jinja2 template engine in webpy

http://webpy.org/cookbook/template_jinja

2. Deployment

##启动端口
python web_console.py 8800

Run On http://host/context

        location /console {
            rewrite    /context/(.*) /$1 break;
            proxy_pass  http://localhost:8800/;
            proxy_set_header   Host             $host;
            proxy_set_header   X-Real-IP       $remote_addr;
            proxy_set_header  X-Forwarded-For  $proxy_add_x_forwarded_for;
        }

3. Reference

MainWiki: webpy (last edited 2016-07-26 21:23:47 by twotwo)