bottle

Bottle文档最新翻译版-1.1.2 Hello World

夙愿已清 提交于 2019-12-06 09:46:50
1.1.2 老一套:"Hello World" 本教程假设你已经安装好了Bottle,接下来我们用一个简单的"Hello World"例子来开始我们的学习: from bottle import route, run @route('/hello') def hello(): return "Hello World!" run(host='localhost', port=8080, debug=True) 双击或者在命令行下面运行这个脚本,然后用你的浏览器访问 http://localhost:8080/hello ,你将会看到浏览器上面显示"Hello World!"这句话,让我们来分析一下这个脚本工作的过程: 首先,route()将它修饰的代码绑定到指定的URL.在这个例子里边,我们将"hello()"这段代码绑定到"/hello"这个路径.让指定URL访问指定代码的行为叫做路由,并且这是Bottle框架里边一个非常重要的概念.你可以自定义任何你需要的路由规则.当浏览器打开你指定的URL的时候,相对应的方法将会被调用运行并且将运行结果发给浏览器.嗯嗯,是不是很简单? 接下来,最后一行代码的run()方法将会启动一个内置的开发级服务器.它运行在本地主机"localhost"的8080端口上面,在你按下Ctrl-C组合键之前,它将会兢兢业业,鞠躬尽瘁地为你响应每一个浏览器请求

What would be the best way to pass a list from python to js using bottle?

怎甘沉沦 提交于 2019-12-06 05:47:38
问题 I am using Bottle as a web server and need to pass a python list to javascript. When I am doing just {{myList}}, Bottle escapes single quotes for strings in the list and shows them as ' JS, in turn, isn't very happy with what it gets. I managed to find a solution, but I don't think it's an optimal one. var tempList = '{{eval(myList)}}'.replace(/'/g, "'"); var myNewList = eval(tempList); I wonder, is there a better way to do this? upd: I moved the solution I found into the 'Answers' section.

Bottle framework generate pdf

倾然丶 夕夏残阳落幕 提交于 2019-12-05 20:54:33
I need to generate PDF document using the Bottle framework. I tried similar to Django but that didn't work: @bottle.route('/pd') def create_pdf(): response.headers['Content-Type'] = 'application/pdf; charset=UTF-8' response.headers['Content-Disposition'] = 'attachment; filename="test.pdf"' from io import BytesIO buffer = BytesIO() from reportlab.pdfgen import canvas p = canvas.Canvas(buffer) p.drawString(100,100,'Hello World') p.showPage() p.save() pdf = buffer.getvalue() buffer.close() response.write(pdf) return response Bottle functions aren't supposed to return the response object, they're

Bottle Template Support?

[亡魂溺海] 提交于 2019-12-05 18:19:17
I'm using PyCharm 3.4.1 and learning MongoDB from Mongo University. In the code, they have us using Python to create html pages using the MVC pattern with bottle. When I add a file of type .tpl to the editor in PyCharm, there is no "intellisense" or support for the model in the code. Changing it to be in the list of html file types helps some, but no python support in the editor. Is there a plugin or some other change i can make to support editing better? Seems someone else asked something similar earlier in the year at How to get tpl files highlighted in pycharm? Bottle comes with a built-in

How to send xml/application format in bottle?

99封情书 提交于 2019-12-05 16:55:12
If some one come to my url suppose /get it should give back a xml/application format in response in bottle framework. How can i do this? i am using elementree as xml generator. Look on the official page for the cookie example and do it like this: @route('/xml') def xml(): response.headers['Content-Type'] = 'xml/application' ....(create the xml here)...... return xml_content_whatever 来源: https://stackoverflow.com/questions/3490744/how-to-send-xml-application-format-in-bottle

Bottle文档最新翻译版-1.1一个简单的小教程

情到浓时终转凉″ 提交于 2019-12-05 13:59:17
1.1 一个简单的教程 这个教程涵盖了Bottle框架里边的基础和一些比较高级的主题,它将会向你介绍框架所包含的概念和功能.你可以从头到尾来阅读它,也可以以后把它作为参考.当然,自动生成的那些个API文档应该也会让你产生一些兴趣,它涵盖了更多的方面,但是不如本教程解释得这么详细.^_^ 我们收集了一些热门问题和相对应的解决办法,放在了"问题集"里边和常见问题解答页面.如果你还需要其他帮助,请加入我们的 邮件列表 或访问我们的 IRC频道 . 来源: oschina 链接: https://my.oschina.net/u/47193/blog/96184

Start a wsgi app from within virtualenv as a Linux system service

不羁的心 提交于 2019-12-05 02:46:15
问题 I'm currently developing a bottle app within virtualenv. I intend to serve it using bjoern WSGI server (but that probably doesn't matter too much). I also intend to serve the app with a lighty or nginx reverse proxy. Anyhow, can the app be run from within its own virtualenv as a system service? And if so, how would one go about it? 回答1: According to my experience, I suggest that you can use Supervisord to run your web server as daemon service. Although you can write some Linux service scripts

Starting python bottle in a thread/Process and another daemon next to it

寵の児 提交于 2019-12-04 21:37:01
Ok, so this may be a little bit unorthodox or I'm just stupid or both :) I'm trying a very simple setup where I start a bottle server in one Process instance and start a smallish TFTP server in another instance. #!/usr/bin/env python import bottle import sys import tftpy from multiprocessing import Process def main(): try: t = Process(target=bottle.run(host='0.0.0.0', port=8080)) t.daemon = True t.start() t.join() h = Process(target=tftpy.TftpServer('/srv/tftp').listen('0.0.0.0', 69)) h.start() h.join() except KeyboardInterrupt: sys.stdout.write("Aborted by user.\n") sys.exit(1) if __name__ ==

How do I access bottle development server from another PC on the LAN?

荒凉一梦 提交于 2019-12-04 17:24:44
问题 I'm running the bottle.py tutorial on one PC, and I was able to access it using http://localhost:8080/hello/world However, when I tried to access it (IP address is 192.168.1.10) from another PC on the LAN, using http://192.168.1.10:8080/hello/world I received the "Cannot Open Page" error. I have the Apache web server running on the PC, and I can access the web server without any problem using http://192.168.1.10 Any suggestions? Thanks. 回答1: Assuming you're talking about the Quickstart:

Standalone Python web server and/or nginx

回眸只為那壹抹淺笑 提交于 2019-12-04 16:51:20
So I've done some reading about Python web frameworks (or servers?), mostly Tornado and Bottle but also FAPWS3 , and there are still some grey areas. First, these three web frameworks are all said to be fast, yet they all include a web server written in Python (except FAPWS3) which should be put behind nginx/Apache. Isn't this reducing the performance? I mean, we know that Python is much slower than C, why not only use nginx, or at worst, only the included Python web server? First of, Tornado and FAPWS3 are web servers, while Bottle is a web framework. Those belong to completely different