bottle

Bottle web app not serving static css files

╄→尐↘猪︶ㄣ 提交于 2019-12-21 04:57:43
问题 My bottle web application is not serving my main.css file despite the fact I am using the static_file method. app.py from bottle import * from xml.dom import minidom @route('/') def index(): return template("index") @route('/glossaryXML') def glossary(): doc_def = minidom.parse("table_definitions.xml") terms = doc_def.getElementsByTagName("str_term") defins = doc_def.getElementsByTagName("str_definition") return template("list", terms=terms, defins=defins) @route('<filename>.css') def

Decorators vs. classes in python web development

孤人 提交于 2019-12-20 22:58:47
问题 I've noticed three main ways Python web frameworks deal request handing: decorators, controller classes with methods for individual requests, and request classes with methods for GET/POST. I'm curious about the virtues of these three approaches. Are there major advantages or disadvantages to any of these approaches? To fix ideas, here are three examples. Bottle uses decorators: @route('/') def index(): return 'Hello World!' Pylons uses controller classes: class HelloController(BaseController)

Bottle + WebSocket

守給你的承諾、 提交于 2019-12-20 09:31:23
问题 is it possible to host a normal Bottle application and a WebSocket one (example: https://github.com/defnull/bottle/blob/master/docs/async.rst) in the same application (same port)? So that /ws will go to WebSocket handler and all other will be normally routed to other bottle handlers. 回答1: It sure is. The server: #!/usr/bin/python import json from bottle import route, run, request, abort, Bottle ,static_file from pymongo import Connection from gevent import monkey; monkey.patch_all() from time

Python bottle - How to upload media files without DOSing the server

五迷三道 提交于 2019-12-20 05:28:33
问题 I was using the answer from this question and saw the comment: raw = data.file.read() # This is dangerous for big files How do I upload the file without doing this? My code so far is: @bottle.route('/uploadLO', method='POST') def upload_lo(): upload_dir = get_upload_dir_path() files = bottle.request.files print files, type(files) if(files is not None): file = files.file print file.filename, type(file) target_path = get_next_file_name(os.path.join(upload_dir, file.filename)) print target_path

Redirecting to a url with POST data using Python Bottle

牧云@^-^@ 提交于 2019-12-18 05:06:35
问题 Is there any way of adding POST data when redirecting to another page? I've built a service that will redirect the user back to whatever page is specified when the service is called. The problem is I can't put any GET parameters on the url due to complex and badly written rewrite rules etc. so I need to send a value with POST. Is there anyway of adding to Bottles redirect(return_url) or using some other lib in Python? 回答1: You may build the response , instead of using the redirect(url) method

running Apache + Bottle + Python

吃可爱长大的小学妹 提交于 2019-12-18 03:38:14
问题 I'm trying to run Bottle.py with Apache and mod_wsgi. I'm running it on windows, using a xampp. python v2.7 My Apache config in httpd: <VirtualHost *> ServerName example.com WSGIScriptAlias / C:\xampp\htdocs\GetXPathsProject\app.wsgi <Directory C:\xampp\htdocs\GetXPathsProject> Order deny,allow Allow from all </Directory> </VirtualHost> My app.wsgi code: import os os.chdir(os.path.dirname(__file__)) import bottle application = bottle.default_app() My hello.py: from bottle import route @route(

Bottle file upload and process

纵然是瞬间 提交于 2019-12-18 02:58:33
问题 I am using Bottle for uploading rather large files. The idea is that when the file is uploaded, the web app run (and forget) a system command with the uploaded file-path as an argument. Except for starting the system command with the correct file-path as an argument I do not need to save the file, but I need to be certain that the file will be available until the process completes the processing. I use the exact code described here: http://bottlepy.org/docs/dev/tutorial.html#post-form-data

How do I return a JSON array with Bottle?

不想你离开。 提交于 2019-12-17 15:53:39
问题 I'm writing an API using Bottle, which so far has been fantastic. However, I've run up against a small hurdle when trying to return a JSON array. Here's my test app code: from bottle import route, run @route('/single') def returnsingle(): return { "id": 1, "name": "Test Item 1" } @route('/containsarray') def returncontainsarray(): return { "items": [{ "id": 1, "name": "Test Item 1" }, { "id": 2, "name": "Test Item 2" }] } @route('/array') def returnarray(): return [{ "id": 1, "name": "Test

“getaddrinfo failed”, what does that mean?

孤街浪徒 提交于 2019-12-17 02:22:59
问题 File "C:\Python27\lib\socket.py", line 224, in meth return getattr(self._sock,name)(*args) gaierror: [Errno 11004] getaddrinfo failed Getting this error when launching the hello world sample from here: http://bottlepy.org/docs/dev/ 回答1: It most likely means the hostname can't be resolved. import socket socket.getaddrinfo('localhost', 8080) If it doesn't work there, it's not going to work in the Bottle example. You can try '127.0.0.1' instead of 'localhost' in case that's the problem. 回答2: The

How to pass html directly to template

最后都变了- 提交于 2019-12-14 04:20:00
问题 I want to pass HTML directly as a parameter in template() . I know I could do something like: %for i in array: <a>{{i}}</a> %end but I need to pass it directly when I call template, I tried replacing &lt and &gt with < > with javascript but that did not work. I want to do this: {{results_of_i_in_array}} and the loop will occur in my main rather than in the template, I never found anyone asking the same question. Note: this question is NOT a duplicate of this question. I am using bottle