How do I create a django rest API for a python script such as this

19 views
Skip to first unread message

Navaneeth Krishnan

unread,
Feb 23, 2015, 3:27:50 PM2/23/15
to django-res...@googlegroups.com

I have a JSON file with data as such :

['dbname' : 'A', 'collection' : 'ACollection', 'fields' : ['name', 'phone_no', 'address']}
['dbname' : 'B', 'collection' : 'BCollection', 'fields' : ['name', 'phone_no', 'address', 'class']}

These are 2 examples amongst many other dictionaries of the same format.

I have a python code that does the following : Accepts 2 inputs from the user - phone_no and dbname. For example, the user enters phone_no as xxxxxxxxxx and dbname as A. The python code then reads the JSON file and matches the user input with the dictionary element having the name of the database as 'A'. It then opens the database 'A', opens the respective collection 'ACollection' and prints the respective fields of posts within the collection that have the phone_no value as xxxxxxxxxx. The databases are implemented with mongoDB.

I need to build a django rest api for this code. The end goal is to access the code from a browser. The user provides the 2 inputs in the browser and the code is executed, returning the data, which is displayed on the browser. I have gone through the django-rest framework documentation but I'm new to this whole concept and would like some guidance.

How do I implement these functions and create an API? What code should the models, serializers, views and urls files have related to my program?

Reply all
Reply to author
Forward
0 new messages