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:Since you didn't define the
post
method, it's the right behavior to get a405 (METHOD NOT ALLOWED) error
.