from bottle import route, run
@route('/hello')
def hello():
return "Hello World!"
run() # This starts the HTTP server
from bottle import route, request
@route('/form/submit', method='POST')
def form_submit():
form_data = request.POST
do_something(form_data)
return "Done"
@route('/hello/:name')
def hello(name):
return "Hello %s!" % name
@route('/get_object/:id#[0-9]+#')
def get(id):
return "Object ID: %d" % int(id)
@route('/get_object/(?P<id>[0-9]+)')
def get(id):
return "Object ID: %d" % int(id)
from bottle import route, validate
# /test/validate/1/2.3/4,5,6,7
@route('/test/validate/:i/:f/:csv')
@validate(i=int, f=float, csv=lambda x: map(int, x.split(',')))
def validate_test(i, f, csv):
return "Int: %d, Float:%f, List:%s" % (i, f, repr(csv))
@route('/get_string')
def get_string():
return "This is not a list of strings, but a single string"
@route('/file')
def get_file():
return open('some/file.txt','r')
@route('/api/status')
def api_status():
return {'status':'online', 'servertime':time.time()}
from bottle import response
response.set_cookie('key','value', path='/', domain='example.com', secure=True, expires=+500, ...)
from bottle import response response.COOKIES['key'] = 'value' response.COOKIES['key']['max-age'] = 500
<h1>Hello {{username}}</h1>
<p>How are you?</p>
%header = 'Test Template'
%items = [1,2,3,'fly']
%include http_header title=header, use_js=['jquery.js', 'default.js']
<h1>{{header.title()}}</h1>
<ul>
%for item in items:
<li>
%if isinstance(item, int):
Zahl: {{item}}
%else:
%try:
Other type: ({{type(item).__name__}}) {{repr(item)}}
%except:
Error: Item has no string representation.
%end try-block (yes, you may add comments here)
%end
</li>
%end
</ul>
%include http_footer
from bottle import default_app, run app = default_app() newapp = YourMiddleware(app) run(app=newapp)
from bottle import route, db
@route('/db/counter')
def db_counter():
if 'hits' not in db.counter:
db.counter.hits = 0
db['counter']['hits'] += 1
return "Total hits: %d!" % db.counter.hits
from bottle import Bottle, run
mybottle = Bottle()
@mybottle.route('/')
def index():
return 'default_app'
run(app=mybottle)
from bottle import PasteServer, FlupServer, FapwsServer, CherryPyServer bottle.run(server=PasteServer) # Example
def run_custom_paste_server(self, host, port): myapp = bottle.default_app() from paste import httpserver httpserver.serve(myapp, host=host, port=port)
# /var/www/yourapp/app.wsgi import bottle # ... add or import your bottle app code here ... # import myapp application = bottle.default_app() # Do NOT use bottle.run() with mod_wsgi
<VirtualHost *>
ServerName example.com
WSGIDaemonProcess yourapp user=www-data group=www-data processes=1 threads=5
WSGIScriptAlias / /var/www/yourapp/app.wsgi
<Directory /var/www/yourapp>
WSGIProcessGroup yourapp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
import bottle from google.appengine.ext.webapp import util # ... add or import your bottle app code here ... # import myapp # Do NOT use bottle.run() with AppEngine util.run_wsgi_app(bottle.default_app())
import bottle # ... add or import your bottle app code here ... bottle.run(server=bottle.CGIServer)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有