-1

I was using function based views and was getting output correctly. However when I changed it to class based views while invoking function I am getting error Method Not Allowed (POST):

views file"

class ChatBot(TemplateView):
    # extend from TemplateView
    template_name = 'bot/chatbot.html'
    //**Getting error in calling bot function**

class MessagePassing(View):
    def bot(request):
        response_data={}
        response_data['input'] = request.POST['message']
        return HttpResponse(json.dumps(response_data),
                        content_type="application/json")
Lemayzeur
  • 8,297
  • 3
  • 23
  • 50

1 Answers1

1

Use def post(self, request): instead of def bot(request).

self is a required argument. Ref: What is the purpose of self?

Use post because bot is not a valid HTTP method. class View expects a valid HTTP method name to be used as the method name.
Ref 1: Handling forms with Class Based Views
Ref 2: _allowed_methods

Sachin
  • 3,576
  • 1
  • 15
  • 24