Python Web S1E3 : CherryPy - List to JSON
In the previous tutorial
we looked at how to render a list in a material list using cherrypy. Cherrypy is an object oriented minimalistic framework that allows us make web apps easily. In this example, let's see how to serve json data from our app. We convert a python list to json data and server it so that client apps can consume it.
Please watch the below video tutorial for more detail.
- To Install Cherrypy use any of the following commands:
pip install cherrypy
You can also get it from github:
git clone https://github.com/cherrypy/cherrypy
python setup.py install
For more information on cherrypy installation please here is detailed guide
- Jinja like cherrypy can installed using easy-install or pip.
pip install Jinja2
Language : Python 3.5, HTML
Platform : Backend and Fronted Web
IDE : PyCharm
Topics : Object Oriented Python, Cherrypy JSON,Python List
Questions this Project answers.
- Cherrypy convert list from python code to json.
- CherryPy web development example
- Python web development.
These are the third party CSS and JS used in this project.
- Here's the screenshot of the project.
[caption id="" align="alignnone" width="1064"]
- Here's the structure of the project.
[caption id="" align="alignnone" width="226"]
Lets have a look at the source code.
- Our Main class.
- Import cherrypy and json.
- Create a function that dumps or prints our list into json
galaxies=["Messier 81","StarBurst","Black Eye","Cosmos Redshift","Sombrero","Hoags Object","Andromeda","Centarus A","Whirlpool","Canis Major Overdensity"]
if __name__ == '__main__':
- For detailed explanation as well as demo please check Video version of this tutorial below.
- You can Download the full Project below:
How to Download and Run.
- Download the project above.
- You'll get a zipped file,extract it.
- Extract and import into your IDE and run.
- Visit our channel for more examples like these.
- Lets share tips and ideas in our Facebook Page.