Joke App using Bottle Framework - Python
Last Updated :
23 Jan, 2023
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 We will create a simple Joke application using Django. By using the pyjokes package, weâll build a web app that generates and displays random jokes. Weâll go step-by-step to set up the project, configure the views, and render jokes dynamically on the homepage.Install Required PackagesFirst, install
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 depende
2 min read
Blackjack console game using Python Blackjack is a popular two-player card game that is played with a deck of standard playing cards around the world in casinos. The main criteria for winning this game are chance and strategy. The challenge of this game is to get as close to 21 points as possible without exceeding them. That is why it
6 min read
Create a Single Executable from a Python Project Creating a single executable from a Python project is a useful way to distribute your application without requiring users to install Python or any dependencies. This is especially important for users who may not be familiar with Python or who need a simple way to run your application on their system
3 min read
Create a Spin the Bottle game using React-Native React-Native is an open-source framework used to develop cross-platform applications i.e., you can write code in React-Native and publish it as an Android or IOS app. In this article, we will build a basic Spin the Bottle game in React-Native. This is a multi-player game. Usually, people sit in a ro
7 min read