PUT method is not working in my django rest frame work.
Models.py
class Profile(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30,blank=True)
Corresponding view
class ProfileDetailsView(APIView):
"""
Get, udpate, a user's profile
"""
template_name = 'users/profile.html'
form_class = UserProfileForm
authentication_classes = (SessionAuthentication,)
def get_object(self, pk):
try:
return Profile.objects.get(pk=pk)
except Profile.DoesNotExist:
raise Http404
def get(self, request, pk, format=None):
print "111111111111111111"
profile = self.get_object(pk)
serializer = UserProfileSerializer(profile)
return render(request, self.template_name, context=serializer.data)
def put(self, request, pk):
print "2222222222222222222"
When I request the page(GET), it displays the corresponding details(profile details). But when I submit the page(PUT) it still goes to get
section instead of put
.
It works well when I use the REST view. The problem is with the web view(html).What I'm missing?
Any help appreciated
HTML page
<form class="form-profile" >{% csrf_token %}
<div class="form-horizontal">
<div class="form-group">
<label class="col-sm-2 control-label">First name</label>
<div class="col-sm-10">
<input value="{{first_name}}" class="form-control" id="first_name" maxlength="255" name="first_name" placeholder="First name" required="required" type="text" />
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Last name</label>
<div class="col-sm-10">
<input value="{{last_name}}" class="form-control" id="last_name" maxlength="255" name="last_name" placeholder="First name" type="text" />
</div>
</div>
</div>
</form>