[Answered ]-In what format should I respond from django to android after getting http get?

1👍

Read about serializing objects in django.

You can choose between xml, json or yaml. It’s pointless to add documentation here. Goto the link.

EDIT: Django’s doc is really nice. Example shouldn’t really be needed. But, still, an example from one of my projects [Line 492-507 from views.py].

def pendingOrders(request):
    userprof = UserProfile.objects.get(user= request.user)
    if userprof.is_student:
        student_account = request.user
        dish = Dishes.objects.all()
        #Getting all pending orders
        order_all_pending = Orders.objects.filter(student_id = student_account,delivered = False)
        pending_orders = Orders.objects.filter(~Q(status = 2),delivered = False)
        for order in order_all_pending:
            #Hack to change QuerySet to pass as JSON 
            order.quantity = pending_orders.filter(id__lt = order.id,counterid= order.counterid).count() + 1

        #Returning JSON response to the objects obtained in above statement
        return HttpResponse(serializers.serialize('json',order_all_pending,use_natural_keys=True),mimetype='application/json')
    else:
        return HttpResponse("Something went wrong")

1👍

https://stackoverflow.com/a/2845612/931277 Has an example of parsing json from an HttpResponse in Android.

0👍

You should use JSON. Django even makes it easy for you.

Leave a comment