bottle

Enable or disable @auth_basic() programmatically

百般思念 提交于 2019-12-13 02:36:53
问题 I'm trying to use the Bottle framework @auth_basic(check_credentials) decorator within my program but I would like to be able to enable it or disable it based on a choice made by the user in program settings. I've tried to do a if inside the check_credentials to return True if the setting is False but I'm still getting the login popup which is always returning True . I would like to not get the popup at all. Any idea how I could achieve that? def check_credentials(user, pw): if auth_enabled =

Unit testing Bottle app with WebTest

杀马特。学长 韩版系。学妹 提交于 2019-12-13 01:43:02
问题 I've been attempting to familiarize myself with unit testing but have been having a lot of trouble with it. I have a bottle app that I tried using Unittest, which didn't seem appropriate, so now I'm trying WebTest. The trouble is that I can't get it to even remotely work, even following along with the most basic/superficial example on the site. Here's the example: from webtest import TestApp import mywebapp def test_functional_login_logout(): app = TestApp(mywebapp.app) app.post('/login', {

python bottle framework - How to pass dictionary to nested template?

和自甴很熟 提交于 2019-12-12 21:18:00
问题 I am using python's bottle framework to develop a simple web page. I am having trouble understanding how to pass a dictionary to a subtemplate. Example code: mydictionary: { message: "Hello World", ...other template vars ... } Router.py @route('/index.html') @view('index.tpl') def index(): return mydictionary views/index.tpl <body> %include subpage1 ...... <-- need to pass mydictionary here ...other stuff ... </body> views/subpage1.tpl <div>This is a test: {{message}}</div> The documentation

How to run server as fixture for py.test

a 夏天 提交于 2019-12-12 18:25:48
问题 I want to write Selenium tests with server as fixture: import pytest @pytest.fixture() def driver(request): from selenium import webdriver d = webdriver.Firefox() request.addfinalizer(d.close) return d @pytest.fixture() def server(): from server import run run(host="localhost", port=8080) def test_can_see_echo(driver,server): page = TestPage(driver) page.fill_text_in_input("test") page.click_send() print page.get_returnet_value() Function run in server fixture is bottle run function. The

How to set wsgi.url_scheme to https in bottle?

六眼飞鱼酱① 提交于 2019-12-12 05:46:56
问题 I want to redirect all requests to http to https . Is there a generic approach to setting wsgi.url_scheme to https in a Python 2.7 bottle application? The general structure of the application is: setup.py // contains 'install_requires' wsgi - myapplication.py // the custom application containing bottle routes wsgi.url_scheme seems to be related to environment variables: http://wsgi.readthedocs.org/en/latest/definitions.html#envvar-wsgi.url_scheme But I'm not sure how to actually 'set' the

How do I access an uploaded file with Bottle?

非 Y 不嫁゛ 提交于 2019-12-12 04:33:47
问题 I'd like to upload a text file with bottle, and then read it. How can I do this? Below is what I've tried and didn't work. HTML: <form action="/load_from_file" method="post"> <div> Load File: <input type="file" name="file"/> <input type="submit" value="Submit"/> </div> </form> Bottle route: @post('/load_from_file') def load_from_file(): list_file = request.forms.get("file") print request.files.get("file") print request.files["file"] return "how do I get the uploaded file?" 回答1: You should add

Truncated output using Python bottle 0.12.8 as a CGI application under Windows on an Apache server

让人想犯罪 __ 提交于 2019-12-12 03:38:41
问题 This is the application: #!/home2/friendv0/Python-2.7.9/bin/python from bottle import Bottle app = Bottle() @app.get('/') def hello(): return """<!DOCTYPE html> <html lang="en"> <head> <title>bottle Test</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta charset="utf-8"> </head> <body> Hello! </body> </html> """ app.run(server='cgi') The resulting output is: <!DOCTYPE html> <html lang="en"> <head> <title>bottle Test</title> <meta name="viewport" content="width

Tornado - mount Bottle app

淺唱寂寞╮ 提交于 2019-12-12 02:54:36
问题 How do you mount Bottle app in Tornado server? Here is my code 回答1: bottle.default_app() returns a WSGI callable: if __name__ == "__main__": bottle_app = bottle.default_app() bottle_handler = tornado.wsgi.WSGIContainer(bottle_app) HTTPServer(Application([(r"/ws", WSHandler), (r"/css/(.*)", StaticFileHandler, {"path": "./css/"}), (r"/js/(.*)", StaticFileHandler, {"path": "./js/"}), (r"/img/(.*)", StaticFileHandler, {"path": "./img/"}), ("/(.*)", bottle_handler)]) ).listen(1024) IOLoop.instance

build a production site with bottle

穿精又带淫゛_ 提交于 2019-12-12 01:55:44
问题 I have built a REST API using Python and Bottle web framework. I have tested it locally and it works well according to my needs. I now need to take it online and have multiple people accessing it, maybe concurrently, to upload video files to be processed. I have read in the bottle documentation information regarding deployment and it seems to me that all I should do is use a load balancer (for example using Pond) and have several bottle processes ready in different ports of my server waiting

How to close the connection

拟墨画扇 提交于 2019-12-12 00:45:14
问题 I'm migrating a simple toolset from python 2.7 to 3.5 and one of the tools is a simple web server using web.py. Unfortunately web.py is not available for 3.5 yet so I switched to bottle.py for this. According to the specification of the interface I'm creating I need to close the connection which I can do quite easily in web.py by adding the following line: web.header('Connection', 'close') But using bottle I get the error that hop-by-hop headers are not allowed when I do the following: