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.
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 app.py
To run flask app you need run this command in your command prompt or terminal:
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”
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.