A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/flask-project-create-a-joke-app-with-pyjokes/ below:

Flask project - Create a Joke App with PyJokes

Flask project - Create a Joke App with PyJokes

Last Updated : 26 May, 2022

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().  

Languages Supported By pyjokes:

Categories Included In pyjokes:

Creating Flask Project - 

I have created a file and name it as app.py

app.py

Python3
from flask import Flask
import pyjokes

app=Flask(__name__)


@app.route("/")
def home():
    joke=pyjokes.get_joke()  #It only returns one joke. We get random joke each time. 
    return f'<h2>{joke}</h2>'

@app.route("/MultipleJokes")
def jokes():
    jokes=pyjokes.get_jokes()  #Here, we get a list of jokes.  
    return f'<h2>{jokes}</h2>'

if __name__ == "__main__":
    app.run(debug=True)

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

For windows

python app.py

For ubuntu

python3 app.py

After running the app you will get output like this 

Output on "http://127.0.0.1:5000" Output on "http://127.0.0.1:5000/MultipleJokes"

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4