model.objects.create in views is not working in my django project?
<p>This is <code>models.py</code></p>

<pre><code>from django.db import models
class Iot(models.Model):
        user = models.CharField(max_length="50")
        email = models.EmailField()
</code></pre>

<p>This is my <code>views.py</code></p>

<pre><code>def Test(request):
    if request.method == 'PUT':
        user = request.data['user']
        email = request.data['email']
        try:
            s = Iot.objects.create(user=user)
            print s.user
            s.email = email
            s.save()
            return Response('ok', status=status.HTTP_200_OK)
       except:
            return Response('error',status=status.HTTP_400_BAD_REQUEST)
</code></pre>

<p>I'm using django rest_framework. When i send data it does not store in database and returns:</p>

<blockquote>
  <p>('error',status=status.HTTP_400_BAD_REQUEST)</p>
</blockquote>

<p>Most likely that error happens because you try to create Iot without email, but it is required field. 
You should do something like</p>

<pre><code>Iot.objects.create(user=user, email=email)
</code></pre>

<p>To make your code working in the way you choose(set attributes one by one and not at once) you need to get rid of create and do the following:</p>

<pre><code>s = Iot(user=user)
s.email = email
s.save()
</code></pre>

<p>there are two different ways to create the entity in the model with on request. Create calls save() method inside, so they are quite the same, but create more handy in this case.</p>

<p>Also normally you should avoid doing create() and then save(), since it will appears two queries to DB.</p>

<p>UPD: +1 to @Daniel's comment about exception</p>

python django django-rest-framework