Skip to main content

The easiest way to use cors on bottle

Project description

The easiest way to implement cors on your bottle py web application

Installing the plugin

pip install bottle-cors-plugin

after this on your bottle app you need to import cors_plugin and install for example.

# -*- coding: utf-8 -*-
from bottle import app, response, route, run
from bottle_cors_plugin import cors_plugin

@route('/', method='GET')
def landing():
  response.content_type = 'application/json'
  return {'status': 'Works'}

#Confugure the server
app = app()
app.install(cors_plugin('*'))

if name == "__main__":
  run(host='localhost', port=7000)

On the cors_plugin function you can send a simple string or array of origins this variable will set globaly on the plugin so you just set-it one time to add * origins just don’t put anything on the function

cors_plugin()

This will return the * origins

cors_plugin('https://google.com')

with just google.com as and origin or

cors_plugin(['https://google.com', 'http://google.com'])

for multiple origins

Aborts

for normal abort errors you need to import the abort of the cors_plugin like this

from bottle_cors_plugin import abort


@route('/', method='GET')
def landing():
  response.content_type = 'application/json'
  abort(500, 'Hola')
  return {'status': 'Works'}

It works with all errors, and for custom error handler just import the cors_headers to apply on the function example like this

# -*- coding: utf-8 -*-
from import_env import os
from bottle import error, response
from bottle_cors_plugin import cors_headers

error_log = error

for status_code in range(200, 600):
@error(status_code)
def errorCustom(error_log):
    cors_headers()
    error_log.content_type = 'application/json'
    return error_log.body

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bottle-cors-plugin-0.1.9.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

bottle_cors_plugin-0.1.9-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file bottle-cors-plugin-0.1.9.tar.gz.

File metadata

  • Download URL: bottle-cors-plugin-0.1.9.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.9.0

File hashes

Hashes for bottle-cors-plugin-0.1.9.tar.gz
Algorithm Hash digest
SHA256 22e5d247700bf9c56caf9aa14fda5534efa00c2d9c1c3e80bc479acd66a907d4
MD5 9e091ce56e7730cb565d7e6dcdb6c978
BLAKE2b-256 194bf410b7a96a08cb835035532ebd40ac9235897b08cfd28581267df55a8397

See more details on using hashes here.

File details

Details for the file bottle_cors_plugin-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: bottle_cors_plugin-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.52.0 CPython/3.9.0

File hashes

Hashes for bottle_cors_plugin-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 3056ea85efa655585748ec4c56b3d2480e715649e1e015da8f1287bb1b62fbf6
MD5 b41fd4ce961443f7e42081c53a49208f
BLAKE2b-256 2d8784047e03b27e2727a0951d55a68606f227132b5796c07258722f97959881

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page