def error500(error): return 'Sorry, server error :/ Import dinaosaur' @error(403) #Unauthorized access def error403(error): return 'Halt, authorized personal only >:)' @error(503) #Server not responding def error503(error): return 'service unavailable: server in maintanance. Try again later :))' @error(504) #Gateway timeout def error504(error): return 'Gateway timeout, lolz' ############################################################################### ############################################################################### # This starts the server # # Access it at http://localhost:8080 ############################################################################### if __name__ == "__main__": from bottle import install, run from wtplugin import WtDbPlugin, WtCorsPlugin install(WtDbPlugin()) install(WtCorsPlugin()) run(host='localhost', port=8080, reloader=True, debug=False, autojson=False)
def delete_item(db, model): if model == None: abort(404, "The item you requested was not found in the database") else: brand= request.forms.get('brand') model = request.forms.get('model') os = request.forms.get('os') image= request.forms.get('image') screensize = request.forms.get('screensize') response.status = 204 db.execute('''DELETE FROM phones WHERE model = ?''', (brand, os, image, screensize, model)) ############################################################################### # # # from bottle import route, run # @route('/todo') #def todo_list(): # c = conn.cursor() # c.execute("SELECT id, task FROM todo WHERE status LIKE '1'") result = c.fetchall() # return str(result) # # # # ############################################################################### @error(404) def error404(error): response.status = 404 response.content_type = 'application/JSON' response_body = {'status': response.status, 'message': error.body} return json.dumps(response_body) @error(500) def error505(code): return 'Oops there is something wrong!' ############################################################################### # Error handling # # TODO (optional): # Add sensible error handlers for all errors that may occur when a user # accesses your API. ############################################################################### ############################################################################### # This starts the server # # Access it at http://localhost:8080 # # If you have problems with the reloader (i.e. your server does not # automatically reload new code after you save this file), set `reloader=False` # and reload manually. # # You might want to set `debug=True` while developing and/or debugging and to # `False` before you submit. # # The installed plugin 'WtPlugin' takes care of enabling CORS (Cross-Origin # Resource Sharing; you need this if you use your API from a website) and # provides you with a database cursor. ############################################################################### if __name__ == "__main__": from bottle import install, run from wtplugin import WtDbPlugin, WtCorsPlugin install(WtDbPlugin()) install(WtCorsPlugin()) run(host='localhost', port=8080, reloader=True, debug=True, autojson=False)