I have the following Class Based View
class SupportView(BaseDetailView):
def render_to_response(self):
if self.request.method == "POST":
message = "YES"
else:
message = "NO"
return HttpResponse(message)
And following Jquery code:
<script>
var username = $('.username').attr('data-username');
$('.destek').click(function(){
$.ajax({
url:"/profiles/support/",
type:"POST",
data:{"username":username, 'csrfmiddlewaretoken': '{{csrf_token}}'},
dataType:"json"
})
})
</script>
And following url
url(r'^support/$', SupportView.as_view())
But when I click the button i see 127.0.0.1:8000/profiles/support/ 405 (METHOD NOT ALLOWED) error. Any ideas ?
You have to implement the post
method in your view:
class SupportView(BaseDetailView):
def post(self, request, *args, **kwargs):
self.object = self.get_object()
context = self.get_context_data(object=self.object)
return self.render_to_response(context)
Since you didn't define the post
method, it's the right behavior to get a 405 (METHOD NOT ALLOWED) error
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With