Django POST method giving 500 internal server error
<p>I am currently working on a Django project. When I am sending a GET request using CURL it is working fine, but in case of POST request it is giving me 500 internal error. I think it has something to do with csrf token and I have no idea what to do with it or how csrf will solve my error.</p>

<p>I have also set DEBUG = False and ALLOWED_HOSTS = ['*'] in settings.py, but then also I am getting the same error: <h1>Server Error (500)</h1></p>

<p>Here is some piece of my code:</p>

<p>urls.py</p>

<pre><code>from django.conf.urls import patterns, url

urlpatterns = patterns(
    'project.views',
    url(r'^users/$', 'userList', name='userList'),
    url(r'^users/(?P&lt;pk&gt;[0-9]+)$', 'userDetail', name='userDetail'),
)
</code></pre>

<p>This is a function from views,py</p>

<pre><code>@api_view(['GET', 'POST'])

def userList(request):
    if request.method == 'GET':
        user = users.objects.all()
        serializer = UsersSerializer(user, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        serializer = UsersSerializer(data=request.DATA)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        else:
            return Response(
            serializer.errors, status=status.HTTP_400_BAD_REQUEST)
</code></pre>

<p>This is the command I am using in the terminal:</p>

<p>curl -X POST <a href="http://127.0.0.1:8000/users/" rel="nofollow noreferrer">http://127.0.0.1:8000/users/</a> -d '{"username":"root", "email":"abc@gmail.com"}' -H "Content-Type: application/json"</p>

<p>Django version number : 1.9</p>

<p>In POSTMAN I am getting the error as:</p>

<p>{
  "username": [
    "This field is required."
  ],
  "email": [
    "This field is required."
  ]
}</p>