Get a user input from browser

9 views
Skip to first unread message

Navaneeth Krishnan

unread,
Feb 23, 2015, 6:45:17 PM2/23/15
to django-res...@googlegroups.com

I have a basic app that returns data retrieved from a mongodb database.

views.py

from django.views.decorators.csrf import csrf_exempt
from rest_framework.decorators import api_view
from rest_framework.response import Response
from pymongo import Connection
from models import App
from serializers import AppSerializer


@csrf_exempt
@api_view(['GET'])
def pgs(request):

#connect to our local mongodb
db = Connection('localhost',27017)
#get a connection to our database
dbconn = db.general
dbCollection = dbconn['data']

if request.method == 'GET':
    #get our collection
    items = []
    for r in dbCollection.find():
        post = App(r["phone_no"],r["name"],r["address"],r["categories"])
        items.append(post)
    serializedList = AppSerializer(items, many=True)
    return Response(serializedList.data)

When I enter the url in the browser that triggers this GET function, I want the user to be able to enter one input field for phone_no, and the posts returned from the mongodb database should be the ones with the matching phone_no field. How do I do this?

Reply all
Reply to author
Forward
0 new messages