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
Python Tutorial - Learn Python Programming Language Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly. It'sA high-level language, used in web development, data science, automation, AI and more.Known fo
10 min read
Python Interview Questions and Answers Python is the most used language in top companies such as Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify and many more because of its simplicity and powerful libraries. To crack their Online Assessment and Interview Rounds as a Python developer, we need to master important Pyth
15+ min read
Python OOPs Concepts Object Oriented Programming is a fundamental concept in Python, empowering developers to build modular, maintainable, and scalable applications. By understanding the core OOP principles (classes, objects, inheritance, encapsulation, polymorphism, and abstraction), programmers can leverage the full p
11 min read
JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav
11 min read
Python Projects - Beginner to Advanced Python is one of the most popular programming languages due to its simplicity, versatility, and supportive community. Whether youâre a beginner eager to learn the basics or an experienced programmer looking to challenge your skills, there are countless Python projects to help you grow.Hereâs a list
10 min read
Python Exercise with Practice Questions and Solutions Python Exercise for Beginner: Practice makes perfect in everything, and this is especially true when learning Python. If you're a beginner, regularly practicing Python exercises will build your confidence and sharpen your skills. To help you improve, try these Python exercises with solutions to test
9 min read
Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De
5 min read
Python Programs Practice with Python program examples is always a good choice to scale up your logical understanding and programming skills and this article will provide you with the best sets of Python code examples.The below Python section contains a wide collection of Python programming examples. These Python co
11 min read
React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications
15+ min read
Python Introduction Python was created by Guido van Rossum in 1991 and further developed by the Python Software Foundation. It was designed with focus on code readability and its syntax allows us to express concepts in fewer lines of code.Key Features of PythonPythonâs simple and readable syntax makes it beginner-frien
3 min read