Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Many frameworks are available in python that allows us to create web pages like a flask, bottle, and Django. This blog will teach us how to create a simple joke app using the bottle framework.
The bottle is a python micro-framework by which you can build the rest API in minutes. It is distributed as a single file module with only Python Standard Library dependency. Bottle helps in creating web development fastly and easily.
Installation
Firstly, we need to install the necessary modules:
pip install bottle
pip install pyjokes
By importing the pyjokes library, we will get funny one-liners, mostly related to programming.
pyjokes Library
Methods
get_joke()
get_jokes
Working
get_joke returns a single joke. We get random jokes every time.
get_jokes returns a list of jokes. And in this also, we get random jokes every time.
Parameter
It consists of two-parameter - language and category.
It also consists of the same parameter i.e. language and category.
Return type
The return type of this method is a string (str).
The return type of this method is the list.
Languages supported by pyjokes are as follows:
English - ‘en’
German - ‘de’
Spanish - ‘es’
Galician - ‘gl’
Basque - ‘eu’
Italian - ‘it’
Categories that are included in pyjokes are as follows:
For ninja jokes: ‘neutral (it is the default value)
For Chris Norris Jokes: ‘chuck.’
If we want all types of types: ‘all.’
One last category in pyjokes is known as “twister,” which works only for the German language (‘de’).
Creating a Project
Now, we first need to create a project called Joke_app.
To run the application, open cmd and type the following command:
python app.py
Output:
Frequently Asked Questions
What is Bottle API?
The bottle is a python micro-framework by which you can just build the rest API in minutes. It is distributed as a single file module and has only Python Standard Library dependency. Bottle helps in creating web development fastly and easily.
What are the two parameters in the get_joke method?
get_joke method consists of two parameters: language and property.
What is the return type of the get_joke and get_jokes methods?
The return type of get_joke is a string, whereas the return type of the get_jokes method is the list.
What two necessary modules are needed for installation?
The two modules needed for the joke app are bottle and pyjokes.
What does WSGI stand for?
The Web Server Gateway Interface (pronounced whiskey or WIZ-ghee) is a straightforward calling standard used by web servers to route requests to web applications or frameworks created in the Python programming language.
Conclusion
This article discussed the bottle framework and how to create a simple joke app using Bottle Framework. We started with the introduction of the bottle framework, and then we saw how to install the bottle module and pyjokes module., and then we saw the methods of pyjokes library and the implementation of the project.