Bottle is a useful framework for various web development scenarios such as:
Prototyping ideas
Learning how web frameworks are built
Building and running simple personal web applications
It is a single file.
It can run as a web server itself or be used behind any web server.
It has a built-in template engine called Simple Template Engine.
It contains various plugins for popular databases.
First of all, we need to install bottle. Write the following command in the terminal:
pip install bottle
In this code, we run the router on the specific host and port address.
The code starts by running the application using this command,
app = bottle.default_app()
.
The user writes the Response which they want to be viewed on the screen. Command:
return Response()
.
Write your string within the brackets of Response()
.
import osimport bottle# import the following features from bottlefrom bottle import route, run, Responseapp = bottle.default_app()@route('/')def index():# Text within response is showed on the localhostreturn Response("Welcome to my bottle. Hello user.")if __name__ == '__main__':port = int(os.environ.get('PORT', 5000))run(host='127.0.0.1', port=port, debug=True)
Open a web browser after executing . You should be able to connect to http://localhost:5000/
and see your application running!
Tada!