亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費注冊 查看新帖 |

Chinaunix

  平臺 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
查看: 6070 | 回復: 0
打印 上一主題 下一主題

[譯]Bottle中文簡介 [復制鏈接]

論壇徽章:
0
跳轉到指定樓層
1 [收藏(0)] [報告]
發(fā)表于 2009-09-24 08:24 |只看該作者 |倒序瀏覽

最新文檔地址:http://pynotes.appspot.com/static/bottle/index.htm


譯者: smallfish  <smallfish.xy@gmail.com>
原文: http://bottle.paws.de/
文檔: 簡體中文
Bottle是一個使用Python語言編寫的符合WSGI規(guī)范Web框架.它提供根據(jù)URL參數(shù)轉發(fā)請求(映射),模板,key/value數(shù)據(jù)庫,內(nèi)置多種第三方WSGI/HTTP服務器適配器和模板引擎.整個框架只有一個文件不依賴第三方擴展庫.
安裝或依賴你可以使用easy_install bottle或下載bottle.py到你工作目錄下.Python版本要求2.5+或3.x(使用2to3轉換)
特性和例子輕量級不需要安裝和配置.你只要獲得一份bottle.py拷貝就可以編碼了!簡單的"Hello World" Bottle應用大致如下:
from bottle import route, run

@route('/')
def index():
    return 'Hello World!'

run(host='localhost', port=8080)就是這么簡單.運行它并打開瀏覽器訪問http://localhost:8080/.
良好的URL風格根據(jù)映射語法提取動態(tài)URL參數(shù).
@route('/hello/:name')
def hello(name):
    return 'Hello, %s' % name獲取使用完整的正則去匹配.
@route('/friends/(?<name>(Alice|Bob))')
def friends(name):
    return 'Hello, %s! Good to see you :)' % name靜態(tài)文件,重定向和HTTP錯誤下面的方法可以方便的處理日常工作.
from bottle import send_file, redirect, abort

@route('/static/:filename')
def static_file(filename):
    send_file(filename, root='/path/to/static/files')

@route('/wrong/url')
def wrong():
    redirect("/right/url")

@route('/restricted')
def restricted():
    abort(401, "Sorry, access denied.")POST,GET,Header和Cookies可以當做一個簡單的dict()來使用
from bottle import request, response

@route('/hello/cookie')
def cookie():
    name = request.COOKIES.get('name', 'Stranger')
    response.header['Content-Type'] = 'text/plain'
    return 'Hello, %s' % name

@route('/hello/cookie', method='POST')
def set_cookie():
    if 'name' in request.POST:
        name = request.POST['name']
        response.COOKIES['name'] = name
    return 'OK'模板Bottle自帶了一個簡單快速的輕量級模板引擎
@get('/hello/template/:names')
def pretty_hello(names):
   names = names.split(',')
   return template('hello', title='Hello World', names=names)這里是模板:
<html>
<head>
  <title>{{title}}</title>
</head>
<body>
  %for name in names:
    <p>Hello, <strong>{{name}}</strong></p>
  %end
</body>
</html>也可以使用mako模板獲得更多功能
from bottle import mako_template as templateHTTP服務器Bottle自帶了HTTP服務器,當然也支持在cherrypy, flup,pastefapws3運行應用.
from bottle import PasteServer
run(server=PasteServer)缺少的特性和Bug缺陷Bottle不包括:
  • ORM:你可以選擇(SQLAlchemy, Elixir)
  • HTML幫助類,會話,認證:自己動手吧
  • 擴展:抱歉還沒有
有些可能不會工作:
  • 在Python 3.x下多文件上傳會有問題,因為cgi.FileStorage修改了.
Benchmark本地使用ApacheBench在我的AMD 2800+(2GB)測試Bottle 0.4.2  run(server=PasteServer)
marc@nava:/work/bottle$ ab -c10 -n1000 http://localhost:8080/template/test
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
...
Server Software:        PasteWSGIServer/0.5
...
Concurrency Level:      10
Time taken for tests:   2.238 seconds
Complete requests:      1000
...
Requests per second:    446.83 [#/sec] (mean)
Time per request:       22.380 [ms] (mean)
Time per request:       2.238 [ms] (mean, across all concurrent requests)授權(MIT)Copyright (c) 2009, Marcel Hellkamp.
Permission is hereby granted, free of charge, to any personobtaining a copy of this software and associated documentation files(the "Software"), to deal in the Software without restriction,including without limitation the rights to use, copy, modify, merge,publish, distribute, sublicense, and/or sell copies of the Software,and to permit persons to whom the Software is furnished to do so,subject to the following conditions:
The above copyright notice and this permission notice shall be included in  all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANYCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THESOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
您需要登錄后才可以回帖 登錄 | 注冊

本版積分規(guī)則 發(fā)表回復

  

北京盛拓優(yōu)訊信息技術有限公司. 版權所有 京ICP備16024965號-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報專區(qū)
中國互聯(lián)網(wǎng)協(xié)會會員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關心和支持過ChinaUnix的朋友們 轉載本站內(nèi)容請注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP