Skip to content
Related Articles

Related Articles

Improve Article

Creating first web application using Bottle Framework – Python

  • Difficulty Level : Easy
  • Last Updated : 04 Jan, 2021

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.

  • Routing: Requests to function-call mapping with support for clean and dynamic URLs.
  • Templates: Fast and pythonic built-in template engine and support for mako, jinja2 and cheetah templates.
  • Utilities: Convenient access to form data, file uploads, cookies, headers and other HTTP-related metadata.
  • Server: Built-in HTTP development server and support for paste, fapws3, bjoern, gae, cherrypy or any other WSGI capable HTTP server.

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

Python3






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

Python3




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 – 

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course




My Personal Notes arrow_drop_up
Recommended Articles
Page :