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 –
Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century.
Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve.
Last Updated :
04 Jan, 2021
Like Article
Save Article
Share your thoughts in the comments
Add Your Comment
Please Login to comment...