Skip to content
Related Articles
Open in App
Not now

Related Articles

Flask project – Create a Joke App with PyJokes

Improve Article
Save Article
  • Last Updated : 26 May, 2022
Improve Article
Save Article

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 libraries flask and pyjokes.

Installation –

First we install flask

pip install flask

Second library installation

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 major 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.

Creating Flask Project – 

I have created a file and name it as


from flask import Flask
import pyjokes
def home():
    joke=pyjokes.get_joke()  #It only returns one joke. We get random joke each time. 
    return f'<h2>{joke}</h2>'
def jokes():
    jokes=pyjokes.get_jokes()  #Here, we get a list of jokes.  
    return f'<h2>{jokes}</h2>'
if __name__ == "__main__":

To run flask app you need run this command in your command prompt or terminal:

For windows


For ubuntu


After running the app you will get output like this 

Output on “”

Output on “”

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!