在瓶子里,如何在一个页面中将一个url跳转到另一个url?
import webbrowser
webbrowser.open('http://localhost:8080/login.html')
Run Code Online (Sandbox Code Playgroud)
我尝试过如上所述,但它没有在一个页面中打开!我希望它是重定向,但不会引发303或302错误!
我想将所有请求重定向http
到https
.
是否有一个通用的方法来设置wsgi.url_scheme
,以https
在Python 2.7瓶的应用程序?
该应用程序的一般结构是:
setup.py // contains 'install_requires'
wsgi
- myapplication.py // the custom application containing bottle routes
Run Code Online (Sandbox Code Playgroud)
wsgi.url_scheme
似乎与环境变量有关:
http://wsgi.readthedocs.org/en/latest/definitions.html#envvar-wsgi.url_scheme
但我不确定如何实际"设置"环境变量https
以及是否可以在setup.py
或myapplication.py
文件中完成.
这里有一段代码:
https://github.com/defnull/bottle/issues/347
def i_am_https_dammit(app):
def https_app(environ, start_response):
environ['wsgi.url_scheme'] = 'https'
return app(environ, start_response)
return https_app
Run Code Online (Sandbox Code Playgroud)
但是我不知道如何实现这个要点,因为我对应用程序的调用是来自软木塞而且只是使用:
application=default_app()
session_opts = {
'session.cookie_expires': True,
'session.encrypt_key': 'please use a random key and keep it secret!',
'session.httponly': True,
'session.timeout': 3600 * 24, # 1 day
'session.type': …
Run Code Online (Sandbox Code Playgroud) 我python bottle
在linux上安装框架时遇到问题.以下是我从中获得的信息uname -a
:
Linux magzilla 3.2.0-38-generic#61-Ubuntu SMP Tue Feb 19 12:18:21 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
我已经安装python 2.7.3
,并pip
在其上.它们都成功建立.下载bottle 0.11
框架后,我尝试安装它,使用sudo apt-get install python-bottle
,我得到以下内容:
sudo apt-get install python-bottle Reading package lists... Done
Building dependency tree Reading state information... Done You
might want to run 'apt-get -f install' to correct these: The following
packages have unmet dependencies: linux-server : Depends:
linux-headers-server (= 3.2.0.39.47) but 3.2.0.53.63 is to be
installed E: …
Run Code Online (Sandbox Code Playgroud) 对于Pycharm中的* .tpl文件,哪种文件关联将正确突出显示?我尝试过HTML和PHP,但似乎都没有100%获得它。
我在Windows计算机上使用bottle和python 2.7。
我正在尝试对瓶子和瓶子进行基准测试以做出一些新的项目决定.我看到瓶子惨不忍睹,而烧瓶似乎有效.我无法相信这些框架相距甚远(是吗?!).我猜我做的事情既简单又错误.我完全搞不清楚为什么.
客户
第一步我尝试使用Wrk作为客户端来生成负载来进行基准测试.我的Wrk cmdline看起来像这样
./wrk -c 20 -d 30 -t 10 --latency http://localhost:8888/hello/world
Run Code Online (Sandbox Code Playgroud)
瓶子
Bottle示例服务器如下所示
#!/usr/bin/env python
from bottle import route, run, template
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
run(host='localhost', port=8888)
Run Code Online (Sandbox Code Playgroud)
基准的输出是
Running 30s test @ http://localhost:8888/hello/world
10 threads and 20 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 6.07s 4.44s 13.38s 55.49%
Req/Sec 184.27 311.26 1.33k 73.56%
Latency Distribution
50% 7.29s
75% 7.42s
90% 13.38s
99% 13.38s
34208 requests in 30.02s, 5.61MB read
Socket errors: …
Run Code Online (Sandbox Code Playgroud) 几年前,我开始开发基于Bottle Web 框架的 Web 应用程序。我当时选择 Bottle 是因为它是最容易启动和快速运行的解决方案,而且我只是在为我的想法构建一个原型。现在,我有几千行代码,我正在寻求进入生产级解决方案。
起初我认为我应该转向一个完整的堆栈框架,例如django或web2py。当我朝着那个方向前进时,我开始只在需要时使用其他框架的各个部分。例如,我实现了 web2py 的数据访问层 (DAL),以便我可以在谷歌应用引擎,现在我正在考虑使用 web2py 的调度程序来管理作业。然后,我开始使用cherrypy作为生产级的网络服务器。我尝试了火箭服务器,但我遇到了更多的错误,所以我更喜欢cherrypy而不是火箭。
我开始考虑重写我的代码以完全使用 web2py 的全栈解决方案;然而,重写我的路由函数以完全迁移到 web2py 的时间似乎很重要,我真的对火箭服务器不满意。
我真的很喜欢 Bottle 的简单性,Bottle 使用装饰器函数将路由映射到函数的方式,以及可扩展性的哲学。
我想知道与任何完整堆栈框架相比,使用 Bottle 进行路由在性能方面是否有任何特定优势。
我感谢任何人对此的建议!
我遇到了当前Python脚本的问题.'progress'变量的目的是在通过其中一个if循环时获取特定值.但是,该程序永远不会超过第一个if语句.看起来好像每个if语句都有自己的变量叫做'progress'.有人可以帮帮我吗?见下面的代码.
from bottle import run, route, template, error, static_file
import RPi.GPIO as GPIO
import time
switch1 = 21
switch2 = 20
switch3 = 26
switch4 = 16
switch5 = 19
led1 = 13
led2 = 12
led3 = 6
led4 = 5
led5 = 25
GPIO.setmode(GPIO.BCM)
GPIO.setup(switch1, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(switch2, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(switch3, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(switch4, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(switch5, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(led1, GPIO.OUT)
GPIO.setup(led2, GPIO.OUT)
GPIO.setup(led3, GPIO.OUT)
GPIO.setup(led4, GPIO.OUT)
GPIO.setup(led5, GPIO.OUT)
@route("/")
def hello():
progress = 0
while True:
if …
Run Code Online (Sandbox Code Playgroud) bottle ×7
python ×4
performance ×2
python-2.7 ×2
architecture ×1
flask ×1
https ×1
if-statement ×1
openshift ×1
pycharm ×1
raspberry-pi ×1
web2py ×1
wsgi ×1