title: "POST /receiver/ HTTP/1.1" 500 137512
body: <p>Server side - Python programming with Django Framework:</p>
  
  <h1>views.py</h1>
  
  <pre><code>from django.http import HttpResponse
  from django.shortcuts import render
  from django.views.decorators.csrf import csrf_exempt
  import django.utils.simplejson as json
  
  @csrf_exempt
  def rcvr(request):
      if request.method=='POST':  
          objs = request.POST.get['username']
          return render(request, "post.html",{'username': username})
      else:
          return HttpResponse("Failure...")
  </code></pre>
  
  <h1>urls.py</h1>
  
  <pre><code>from django.conf.urls import patterns, include, url
  from django.contrib import admin
  from receiver import views
  admin.autodiscover()
  urlpatterns = patterns('',
      # Examples:
      # url(r'^$', 'woodpecker.views.home', name='home'),
      # url(r'^woodpecker/', include('woodpecker.foo.urls')),
      # Uncomment the admin/doc line below to enable admin documentation:
      # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
      # Uncomment the next line to enable the admin:
      url(r'^admin/', include(admin.site.urls)),
      url(r'^receiver/', views.rcvr, name='rcvr'),
  )
  </code></pre>
  
  <h1>rcvr.html</h1>
  
  <pre><code>&lt;html&gt;
      &lt;head&gt;&lt;/head&gt;
      &lt;body&gt;        
          &lt;form action="{% url 'woodpecker.receiver.views.rcvr' %}" method="post"&gt;{% csrf_token %}
              &lt;input type="text" name="username"&gt;
              &lt;input type="submit" id="click1" value="username"&gt;
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Client Side - Android Application</p>
  
  <pre><code>package com.example.postjson;
  
  import java.io.IOException;
  import java.io.UnsupportedEncodingException;
  import org.apache.http.HttpResponse;
  import org.apache.http.client.*;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.entity.StringEntity;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.json.JSONObject;
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.Menu;
  
  public class MainActivity extends Activity{
      @Override
      protected void onCreate(Bundle savedInstanceState){
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          HttpClient httpclient = new DefaultHttpClient();         
          try{
              HttpPost post = new HttpPost("http://10.0.2.2:8000/receiver/");
              post.setHeader("Content-type", "application/json");
              post.setHeader("Accept","application/json");
              JSONObject obj=new JSONObject();
              obj.put("username", "abcd");
              obj.put("password","1234");
              post.setEntity(new StringEntity(obj.toString(),"UTF-8"));
              System.out.println("Yo...Yo...!! B-) ");             
  
              HttpResponse response = httpclient.execute(post);
  
              }catch (UnsupportedEncodingException e) {
                  e.printStackTrace();
              }catch (ClientProtocolException e) {
                  e.printStackTrace();
              }catch (IOException e) {
                  e.printStackTrace();
              }catch(NullPointerException e){
                  e.printStackTrace();
              }catch(Exception e){
                  e.printStackTrace();
              }
          }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu){
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  }
  </code></pre>
  
  <p>and whenever i run my app from the simulator, i get the 500 error...</p>
  
  <pre><code>[root@vivek-vaio woodpecker]# python manage.py runserver
  Validating models...
  
  0 errors found
  January 31, 2014 - 20:04:54
  Django version 1.5.4, using settings 'woodpecker.settings'
  Development server is running at http://127.0.0.1:8000/
  Quit the server with CONTROL-C.
  [31/Jan/2014 20:04:57] "GET /receiver/ HTTP/1.1" 200 10
  [01/Feb/2014 09:55:21] "POST /receiver/ HTTP/1.1" 500 137512
  Internal Server Error: /receiver/
  Traceback (most recent call last):
      File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 115, in get_response
      response = callback(request, *callback_args, **callback_kwargs)
      File "/usr/lib/python2.7/site-packages/django/views/decorators/csrf.py", line 77, in  wrapped_view
      return view_func(*args, **kwargs)
      File "/home/vivek/PROJECT/Server_Work/woodpecker/receiver/views.py", line 21, in rcvr
      return render(request, "rcvr.html",{'username': objs})
      File "/usr/lib/python2.7/site-packages/django/shortcuts/__init__.py", line 53, in render
      return HttpResponse(loader.render_to_string(*args, **kwargs),
      File "/usr/lib/python2.7/site-packages/django/template/loader.py", line 177, in render_to_string
      return t.render(context_instance)
      File "/usr/lib/python2.7/site-packages/django/template/base.py", line 140, in render
      return self._render(context)
      File "/usr/lib/python2.7/site-packages/django/template/base.py", line 134, in _render
      return self.nodelist.render(context)
      File "/usr/lib/python2.7/site-packages/django/template/base.py", line 830, in render
      bit = self.render_node(node, context)
      File "/usr/lib/python2.7/site-packages/django/template/debug.py", line 74, in render_node
      return node.render(context)
      File "/usr/lib/python2.7/site-packages/django/template/defaulttags.py", line 404, in render
      raise NoReverseMatch("'url' requires a non-empty first argument. "
      NoReverseMatch: 'url' requires a non-empty first argument. The syntax changed in Django 1.5, see the docs.
  [01/Feb/2014 09:55:33] "POST /receiver/ HTTP/1.1" 500 137512
  </code></pre>
  
  <p>Can anybody please help me?? with the 500 error???</p>