Trouble while providing webservices in django python to android
<p>I am new for Django1.10 Python.</p>

<p>I've to provide web services for an app. So I created a web service in python's Django framework. The web service is properly working for <code>iOS</code> but getting issue while handling with <code>android</code>. For dealing with web services in android, using <code>Volley</code> library.</p>

<p>Following error occurring:-
<code>Error Code 500 Internal Server Error</code></p>

<p>So unable to POST data through android end...</p>

<p>For Web service I am using following code :-</p>

<p><code>views.py</code></p>

<pre><code>from django.http import HttpResponseRedirect, HttpResponse
from django.views.decorators import csrf
from django.views.decorators.csrf import csrf_protect, csrf_exempt
from django.db import IntegrityError, connection
from django.views.decorators.cache import cache_control
from django.core.files.images import get_image_dimensions                
import json
from json import loads, dump
from models import Gym


@csrf_exempt
def gym_register_web(request):

    data = json.loads(request.body)
    gN = str(data['gym_name'])
    gPh = str(data['gym_phone'])
    gE = str(data['gym_email'])
    gL = str(data['gym_landmark'])
    gAdd = str(data['gym_address'])

    exE = Gym.objects.filter(gym_email = gE)

    if exE:
        status = 'failed'
        msg = 'EmailId already exist'
        responseMsg = '{\n "status" : "'+status+'",\n "msg" : "'+msg+'"\n}'
        return HttpResponse(responseMsg)
    else:
        gymI = Gym(gym_name = gN, gym_phone = gPh, gym_email = gE, gym_area = gL, gym_address = gAdd)
        gymI.save()
        data = Gym.objects.get(gym_email = gE)
        status = 'success'
        dataType = 'gym_id'
        val = str(data.gym_id)
        responseMsg = '{\n "status" : "'+status+'",\n "'+dataType+'" : "'+val+'"\n}'
        return HttpResponse(responseMsg)
</code></pre>

<p><code>urls.py</code></p>

<pre><code>from django.conf.urls import url, include
from . import views
from django.views.decorators.csrf import csrf_protect, csrf_exempt
admin.autodiscover()

urlpatterns=[
    url(r'^gymRegister/$', views.gym_register_web),
    ]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
</code></pre>

<p>EDIT:
<code>models.py</code></p>

<pre><code>from django.db import models
from django.contrib import admin

class Gym(models.Model):
    gym_id = models.AutoField(primary_key = True)
    gym_name = models.CharField(max_length = 100, null=True,default = None )
    gym_email = models.CharField(max_length = 100, null=True,default = None )
    gym_phone = models.BigIntegerField(null=True,default = None )
    gym_area = models.TextField(max_length = 255, null=True,default = None )
    gym_address = models.TextField(max_length = 255, null=True,default = None )
    gym_latitude = models.CharField(max_length = 100, null=True,default = None )
    gym_longitude = models.CharField(max_length = 100, null=True,default = None )
    gym_status = models.IntegerField(null=True,default = None )
    gym_website = models.CharField(max_length = 255,null=True,default = None )
    gym_ladies_special = models.IntegerField(null=True,default = None )
</code></pre>

<p>I tested web service on <code>Advance REST Client</code> providing desired output,
and I would like to remind once again the web service is properly working for <code>iOS</code></p>

<p>So, Where Should I improve my code...?</p>

<p>Thanks in Advance :)</p>

<p>EDIT:</p>

<p>my android developer trying to send data in json object manner</p>

<pre><code>{ "key1"="val1", "key2"="val2"}
</code></pre>

<p>instead sending it in json array(key:value) manner</p>

<pre><code>{
    "key1" : "val1",
    "key2" : "val2"
}
</code></pre>

<p>How can I fetch data sent in <code>object</code> format...</p>

<p>ThankYou</p>

<ol>
<li>Make sure that in your 'request.body', you are getting a proper dictionary which have all the keys u accessed below.Because,if your 'data' variable dont have any key that you accessed below, it will raise keyerror and u didnt handle keyerror in your code.  </li>
</ol>

<p>If above does not worked, then show me your models.py</p>

android python web-services django-1.10