Skip to content

Commit

Permalink
Merge pull request #45 from leiqin/master
Browse files Browse the repository at this point in the history
Update some chinese file
  • Loading branch information
aaronsw committed Dec 12, 2012
2 parents 7cd4879 + 23db59a commit 5636c91
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 18 deletions.
15 changes: 14 additions & 1 deletion cookbook/application_processors.zh-cn.md
Expand Up @@ -30,4 +30,17 @@ web.py可以在处理请求之前或之后,通过添加处理器(processor)来
print "my unload hook" print "my unload hook"


app.add_processor(web.loadhook(my_loadhook)) app.add_processor(web.loadhook(my_loadhook))
app.add_processor(web.unloadhook(my_unloadhook)) app.add_processor(web.unloadhook(my_unloadhook))

你可以在钩子中使用和修改全局变量,比如:web.header()

def my_loadhook():
web.header('Content-type', "text/html; charset=utf-8")

app.add_processor(web.loadhook(my_loadhook))

###提示: 你也可以在钩子中使用 web.ctx 和 web.input() 。

def my_loadhook():
input = web.input()
print input
4 changes: 2 additions & 2 deletions cookbook/cookies.zh-cn.md
Expand Up @@ -75,8 +75,8 @@ title: 如何操作Cookie


class CookieGet: class CookieGet:
def GET(self): def GET(self):
age=web.cookies().get(age) age=web.cookies().get('age')
if age: if age:
return "Your age is: %s" % age return "Your age is: %s" % age
else: else:
return "Cookie does not exist." return "Cookie does not exist."
4 changes: 2 additions & 2 deletions cookbook/sessions.zh-cn.md
Expand Up @@ -70,6 +70,6 @@ web.py在处理请求之前,就加载session对象及其数据;在请求处
* cookie_domain - 保存session id的Cookie的domain信息 * cookie_domain - 保存session id的Cookie的domain信息
* timeout - session的有效时间 ,以秒为单位 * timeout - session的有效时间 ,以秒为单位
* ignore_expiry - 如果为True,session就永不过期 * ignore_expiry - 如果为True,session就永不过期
* ignore_change_ip - 如果为true,就表明只有在访问该session的IP与创建该session的IP完全一致时,session才被允许访问。 * ignore_change_ip - 如果为False,就表明只有在访问该session的IP与创建该session的IP完全一致时,session才被允许访问。
* secret_key - 密码种子,为session加密提供一个字符串种子 * secret_key - 密码种子,为session加密提供一个字符串种子
* expired_message - session过期时显示的提示信息。 * expired_message - session过期时显示的提示信息。
34 changes: 31 additions & 3 deletions cookbook/staticfiles.zh-cn.md
Expand Up @@ -5,11 +5,39 @@ title: 提供静态文件 (诸如js脚本, css样式表和图象文件)


# 提供静态文件 (诸如js脚本, css样式表和图象文件) # 提供静态文件 (诸如js脚本, css样式表和图象文件)


### 问题 ## 问题
如何在web.py自带的web server中提供静态文件访问? 如何在web.py自带的web server中提供静态文件访问?


### 解法 ## 解法


### web.py 服务器
在当前应用的目录下,创建一个名为static的目录,把要提供访问的静态文件放在里面即可。 在当前应用的目录下,创建一个名为static的目录,把要提供访问的静态文件放在里面即可。


例如, 网址 <code>http://localhost/static/logo.png</code> 将发送 <code>./static/logo.png</code> 给客户端。 例如, 网址 <code>http://localhost/static/logo.png</code> 将发送 <code>./static/logo.png</code> 给客户端。

### Apache
在 Apache 中可以使用 [Alias](http://httpd.apache.org/docs/2.2/mod/mod_alias.html#alias) 指令,在处理 web.py 之前将请求映射到指定的目录。

这是一个在 Unix like 系统上虚拟主机配置的例子:

<VirtualHost *:80>
ServerName example.com:80
DocumentRoot /doc/root/
# mounts your application if mod_wsgi is being used
WSGIScriptAlias / /script/root/code.py
# the Alias directive
Alias /static /doc/root/static
<Directory />
Order Allow,Deny
Allow From All
Options -Indexes
</Directory>
# because Alias can be used to reference resources outside docroot, you
# must reference the directory with an absolute path
<Directory /doc/root/static>
# directives to effect the static directory
Options +Indexes
</Directory>
</VirtualHost>
4 changes: 2 additions & 2 deletions cookbook/url_handling.zh-cn.md
Expand Up @@ -29,7 +29,7 @@ web.py的URL控制模式是简单的、强大的、灵活的。在每个应用


http://localhost/myapp/greetings/hello?name=Joe http://localhost/myapp/greetings/hello?name=Joe


这个URL的路径是 _/myapp/greetings/hello_。web.py会在内部给URL路径加上^和$ ,这样 _/tasks/_ 不会匹配 _/tasks/addnew_。URL匹配依赖于“路径”,所以不能这样使用,如: _/tasks/delete?name=(.+)_ ,?之后部分表示是“查询”,并不会被匹配。阅读URL组件的更多细节,请访问[web.ctx](ctx.zh-cn) 这个URL的路径是 _/myapp/greetings/hello_。web.py会在内部给URL路径加上^ 和$ ,这样 _/tasks/_ 不会匹配 _/tasks/addnew_。URL匹配依赖于“路径”,所以不能这样使用,如: _/tasks/delete?name=(.+)_ ,?之后部分表示是“查询”,并不会被匹配。阅读URL组件的更多细节,请访问[web.ctx](ctx.zh-cn)


`捕捉参数` `捕捉参数`


Expand All @@ -47,4 +47,4 @@ web.py的URL控制模式是简单的、强大的、灵活的。在每个应用


`开发子程序的时候注意` `开发子程序的时候注意`


为了更好的控制大型web应用,web.py支持[子程序](subapp.zh-cn)。在为子程序设计URL模式的时候,记住取到的路径(web.ctx.path)是父应用剥离后的。比如,你在主程序定义了URL"/blog"跳转到'blog'子程序,那没在你blog子程序中所有URL都是以"/"开头的,而不是"/blog"。查看[web.ctx](ctx.zh-cn)取得更多信息。 为了更好的控制大型web应用,web.py支持[子程序](subapp.zh-cn)。在为子程序设计URL模式的时候,记住取到的路径(web.ctx.path)是父应用剥离后的。比如,你在主程序定义了URL"/blog"跳转到'blog'子程序,那没在你blog子程序中所有URL都是以"/"开头的,而不是"/blog"。查看[web.ctx](ctx.zh-cn)取得更多信息。
4 changes: 2 additions & 2 deletions cookbook/xmlfiles.zh-cn.md
Expand Up @@ -37,7 +37,7 @@ title: 提供XML访问
class index: class index:
def GET(self, code): def GET(self, code):
web.header('Content-Type', 'text/xml') web.header('Content-Type', 'text/xml')
return render.index(code) return render.response(code)


web.webapi.internalerror = web.debugerror web.webapi.internalerror = web.debugerror
if __name__ == '__main__': app.run() if __name__ == '__main__': app.run()
4 changes: 2 additions & 2 deletions docs/0.3/templetor.zh-cn.md
@@ -1,6 +1,6 @@
--- ---
layout: default layout: default
title: Templetor: web.py 模板系统 title: Templetor web.py 模板系统
--- ---


# Templetor: web.py 模板系统 # Templetor: web.py 模板系统
Expand Down Expand Up @@ -272,4 +272,4 @@ web.py 的模板语言叫做 `Templetor`,它能负责将 python 的强大功
以下写法仍被支持,但不被推荐。 以下写法仍被支持,但不被推荐。


* 如果你原来用 `\$` 反转美元字符串, 推荐用 `$$` 替换; * 如果你原来用 `\$` 反转美元字符串, 推荐用 `$$` 替换;
* 如果你有时会修改 `web.template.Template.globals`,建议通过向 `web.template.render` 传变量方式来替换。 * 如果你有时会修改 `web.template.Template.globals`,建议通过向 `web.template.render` 传变量方式来替换。
18 changes: 14 additions & 4 deletions install.zh-cn.md
Expand Up @@ -26,7 +26,11 @@ title: 安装


安装web.py, 请先下载: 安装web.py, 请先下载:


http://webpy.org/static/web.py-0.33.tar.gz http://webpy.org/static/web.py-0.37.tar.gz

或者获取最新的开发版:

https://github.com/webpy/webpy/tarball/master


解压并拷贝 _web_ 文件夹到你的应用程序目录下。 或者,为了让所有的应用程序都可以使用,运行: 解压并拷贝 _web_ 文件夹到你的应用程序目录下。 或者,为了让所有的应用程序都可以使用,运行:


Expand All @@ -43,6 +47,10 @@ title: 安装


easy_install web.py easy_install web.py


或者 [PIP](http://packages.python.org/distribute/)

sudo pip install web.py

<a name="dev"></a> <a name="dev"></a>
## 开发 ## 开发


Expand Down Expand Up @@ -210,7 +218,8 @@ mod_python 运行方式如同FastCGI, 但不是那么方便配置。


重命名 `code.py``codep.py` 或别的名字, 添加: 重命名 `code.py``codep.py` 或别的名字, 添加:


main = web.wsgifunc(web.webpyfunc(urls, globals())) app = web.application(urls, globals())
main = app.wsgifunc()


`.htaccess` 中, 添加: `.htaccess` 中, 添加:


Expand All @@ -231,7 +240,8 @@ mod\_wsgi 是一个新的Apache模块 [通常优于mod_python](http://code.googl


`code.py` 的最后添加: `code.py` 的最后添加:


application = web.wsgifunc(web.webpyfunc(urls, globals())) app = web.application(urls, globals(), autoreload=False)
application = app.wsgifunc()


mod\_wsgi 提供 [许多可行方法](http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives) 来实现WSGI应用, 但一种简单的方法是添加以下到 .htaccess: mod\_wsgi 提供 [许多可行方法](http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives) 来实现WSGI应用, 但一种简单的方法是添加以下到 .htaccess:


Expand Down Expand Up @@ -266,4 +276,4 @@ mod\_wsgi 提供 [许多可行方法](http://code.google.com/p/modwsgi/wiki/Conf
RewriteRule ^(.*)$ code.py/$1 [PT] RewriteRule ^(.*)$ code.py/$1 [PT]
</IfModule> </IfModule>


如果 `code.py` 在子目录 `myapp/`中, 调整 RewriteBase 为 `RewriteBase /myapp/`。 如果还有一些静态文件如CSS文件和图片文件, 复制这些并改成你需要的地址。 如果 `code.py` 在子目录 `myapp/`中, 调整 RewriteBase 为 `RewriteBase /myapp/`。 如果还有一些静态文件如CSS文件和图片文件, 复制这些并改成你需要的地址。

0 comments on commit 5636c91

Please sign in to comment.