Open In App

Joke App using Bottle Framework – Python

Last Updated : 23 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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.

Installation

First we have to install the necessary modules

pip install bottle
pip install pyjokes

You  get funny one-liner, mostly related to programming by using just importing a library known as pyjokes.

Some Methods Of pyjokes Library

There are two methods in pyjokes- get_joke() and get_jokes().  

get_joke()– It only returns one joke. We get random joke each time.

Parameters – There are two parameters- language and category. You can choose from the language and category above.

Return Type – It return string type (str).

get_jokes() – Here, we get a list of jokes.  

Parameter– The parameters are same as above- language and category.

Return type– list.

Languages Supported By pyjokes:

  • English – ‘en’
  • German – ‘de’
  • Spanish – ‘es’
  • Galician – ‘gl’
  • Basque – ‘eu’
  • Italian – ‘it’

Categories Included In pyjokes:

  • For geeky jokes -’neutral’ (It is chosen by default)
  • For Chris Norris Jokes – ‘chuck’.
  • If you want all type of jokes – ‘all’
  • There is one more category known as ‘twister’ which only works for the German Language (‘de’). This mostly includes tongue twister.

Create new directory for project Joke_app

Inside that create a file app.py

Python3




from bottle import route, run, template
import pyjokes
 
@route('/')
def index():
    joke=pyjokes.get_joke()
    return template('index.tpl',{'joke':joke})
 
 
run(host='localhost', port=8080,debug=True)


Then create new directory and name it as views

Inside that create new file index.tpl

HTML




<html>
    <head>
        <title>GFG</title>
    </head>
    <body>
         <h1>{{joke}}</h1>
    </body>
</html>


To run the app open terminal or cmd

python app.py

Output :-



Similar Reads

Joke Application Project Using Django Framework
Django is a high-level Python-based Web Framework that allows rapid development and clean, pragmatic design. It is also called batteries included framework because Django provides built-in features for everything including Django Admin Interface, default database SQLlite3, etc. Today we will create a Joke app in Django. Installation pip3 install dj
2 min read
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 Pyth
2 min read
Introduction to Bottle Web Framework - Python
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. Rout
2 min read
Flask project - Create a Joke App with PyJokes
Flask is a micro web framework written in Python. It is classified as a micro-framework because it does not require particular tools or libraries. Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications. For creating joke app we need two libra
2 min read
How to Install python 'bottle package' on Linux?
py-bottle is a lightweight micro-framework for developing small web apps and it supports request dispatching (Routes) with URL parameter support, templates, a built-in HTTP Server, and adapters for several third-party WSGI/HTTP-server and template engines are all included in a single file with no dependencies except the Python standard library. In
2 min read
Wikipedia search app using Flask Framework - Python
Flask is a micro web framework written in Python. It is classified as a micro-framework because it does not require particular tools or libraries. Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications. Installation: 1) In order to create the
2 min read
Create a Counter App Using React, Tailwind and Django Framework
This article will guide you in creating a Counter using React and Tailwind with the Django Framework. We’ll explore the integration of Django, React, and Tailwind, and go through the step-by-step process of implementing the Counter in Python using the Django Framework. What is Counter App?The Counter app is a straightforward tool designed for easy
6 min read
Kivy - Python Framework for Mobile App development
Kivy is a free and open-source Python library used for developing mobile applications and other multitouch application software with a Natural User Interface. Installation We can download the latest version of Kivy from here. After opening the link you can choose your Platform and follow the instructions specific for your platform. Installation usi
2 min read
Sending Email using FastAPI Framework in Python
Before jumping into the topic directly, let's have a small intro about the technologies we are going to use. As the name suggests, we will be using FastAPI, a Python language framework. FastAPI: FastAPI is a python framework to develop REST Apis. It is very easy to build, high performance, easy to learn, and ready to deploy code. Though we are usin
3 min read
Convert CSV to HTML Table using Python Pandas and Flask Framework
In this article, we are going to convert a CSV file into an HTML table using Python Pandas and Flask Framework. Sample CSV file : USERNAME,IDENTIFIER,FIRST_NAME,LAST_NAME booker12,9012,Rachel,Booker grey07,2070,Laura,Grey johnson81,4081,Craig,Johnson jenkins46,9346,Mary,Jenkins smith79,5079,Jamie,SmithStepwise ImplementationCreating Environment Ste
2 min read
Practice Tags :