Open In App

Creating first web application using Bottle Framework – Python

There are many frameworks in python which allow you to create a webpage like bottle, flask, django. In this article, you will learn how to create a simple app using bottle web framework. Bottle is a fast, simple and lightweight WSGI micro web-framework for Python. It is distributed as a single file module and has no dependencies other than the Python Standard Library.

In order to create the app using bottle, we have to install it first



pip install bottle

Example 1:

Create a file called app.py






from bottle import route, run
  
@route('/')
def index():
    return f'<b>Hello GFG</b>!'
  
run(host='localhost', port=8000,debug=True)

To run this app open command prompt and run

python app.py

Output – 

You can also add variables in your webapp, well you might be thinking about how it’ll help you, it’ll help you to build an URL dynamically. So let’s figure it out with an example.

Example 2:

Create a file called app.py




from bottle import route, run, template
  
  
@route('/hello/<name>')
def index(name):
    return template('<h2>Hello {{name}}</h2>!', name=name)
  
  
run(host='localhost', port=8080)

Output – 


Article Tags :