Introduction to Bottle Web Framework - Python
Last Updated :
16 Mar, 2021
There are many frameworks in python which allows you to create webpage like bottle, flask, django. In this article you will learn how to create simple app bottle.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
Windows
pip install bottle
Ubuntu
pip3 install bottle
By default, if we pass a template name to the SimpleTemplate and it will look for a file by that name in a subdirectory views with the extension .tpl.
First we have to create the directory for our project Test_project
Inside that create a file and name it as app.py
app.py
Python3
from bottle import route, run, template
@route('/')
def index():
return template('index.tpl')
run(host='localhost', port=8080,debug=True)
Then create the new directory views
Inside that create a file index.tpl
HTML
<html>
<head>
<title>GFG</title>
</head>
<body>
<h1>Welcome to GFG</h1>
</body>
</html>
To run this app open cmd or terminal
Windows
python app.py
Ubuntu
python3 app.py
Output :
To handle POST method in bottle we have to write two functions one for GET method and one for POST method.
Python3
from bottle import get,post,request,Bottle,run,template
app = Bottle()
@app.get('/updateData') # For GET method
def login_form():
return template('index.tpl')
@app.post('/updateData') #For POST method
def submit_form():
name = request.forms.get('name')
print(name)
return f'<h1>{name}</h1>'
run(app, host='0.0.0.0', port=8000)
Inside views directory create new file forms.tpl
HTML
<html>
<head>
<title>GFG</title>
</head>
<body>
<form method="post" action="/updateData">
<input type="text" name="name">
<button type="submit">Save</button>
</form>
</body>
</html>
To run this app open cmd or terminal
Windows
python app.py
Ubuntu
python3 app.py
Output :

Similar Reads
Introduction to Sanic Web Framework - Python WHAT IS SANIC? Sanic is an asynchronous web framework and web server for Python 3.5+ thatâs written to go fast. Sanic was developed at MagicStack and is based on their uvloop event loop, which is a replacement for Python asyncioâs default event loop, thereby making Sanic blazing fast. Syntactically
6 min read
Introduction to JustPy | A Web Framework based on Python JustPy is a web framework that leverages the power of Python to create web applications effortlessly. In this article, we'll explore JustPy, its features, and why it's gaining attention among developers. What is the JustPy Module of Python?The JustPy module of Python is a web framework like Django b
8 min read
Introduction to NiceGUI - A Python based UI framework In this article, we will learn about NiceGUI, It is a Python-based UI Framework, which shows up in Web Browsers and we can create buttons, dialogs, Markdown, 3D scenes, plots, and much more. It works well for dashboards, robotics initiatives, smart house solutions, and other related use cases. Addit
5 min read
Introduction to Tornado Framework Tornado is a robust Python asynchronous networking library and web framework, is available as an open-source project. Given that it is made to manage non-blocking, asynchronous processes, it is appropriate for developing high-performance, scalable web apps. Since its creation, Tornadoâwhich was firs
3 min read
Python Falcon Introduction Python Falcon is a lightweight, high-performance web framework that's well-suited for building RESTful APIs. It's easy to learn, efficient, and perfect for projects where speed and simplicity are priorities. In this article, we introduced Falcon and created a basic "Hello World" application to help
4 min read