Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8566797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T17:44:18+00:00 2026-06-11T17:44:18+00:00

I have this: handlers.py class ChatHandler(BaseHandler): model = ChatMsg allowed_methods = (‘POST’,’GET’) def create(self,

  • 0

I have this:

handlers.py

class ChatHandler(BaseHandler):
    model = ChatMsg
    allowed_methods = ('POST','GET')

    def create(self, request, text):
        message = ChatMsg(user = request.user, text = request.POST['text'])
        message.save()
        return message

template.html

    ...
    <script type="text/javascript">
    $(function(){
        $('.chat-btn').click(function(){
            $.ajax({
                url: '/api/post/',
                type: 'POST',
                dataType: 'application/json',
                data: {text: $('.chat').val()}
            })
        })
    })
    </script>
    ...

api/urls.py

chat_handler = Resource(ChatHandler, authentication=HttpBasicAuthentication)
urlpatterns = patterns('',
    ....
    url(r'^chat/$', chat_handler, {'emitter_format': 'json'}),
)

Why, but POST method is allowed in ChatHandler? GET method is working. Is it bug, or my code is wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T17:44:20+00:00Added an answer on June 11, 2026 at 5:44 pm

    Even though you didn’t include this code in your question, I found it in your github you gave in comments…

    You are mapping to a handler that does not allow POST requests

    urls.py ::snip::

    post_handler = Resource(PostHandler, authentication=auth)
    chat_handler = Resource(ChatHandler, authentication=auth)
    urlpatterns = patterns('',
        url(r'^post/$', post_handler , { 'emitter_format': 'json' }),
        url(r'^chat/$', chat_handler, {'emitter_format': 'json'}),
    )
    

    handlers.py

    # url: '/api/post'
    # This has no `create` method and you are not 
    # allowing POST methods, so it will fail if you make a POST
    # request to this url
    class PostHandler(BaseHandler):
        class Meta:
            model = Post
    
        # refuses POST requests to '/api/post'
        allowed_methods = ('GET',)
    
    
        def read(self, request):
            ...
    
    # ur;: '/api/chat'
    # This handler does have both a POST and GET method allowed.
    # But your javascript is not sending a request here at all.
    class ChatHandler(BaseHandler):
        class Meta:
            model = ChatMsg
        allowed_methods = ('POST', 'GET')
    
        def create(self, request, text):
            ...
    
        def read(self, request):
            ...
    

    Your javascript requests is being sent to '/api/post/', which is being routed to the PostHandler. I get the sense that you expected it to go to the chat handler. That means you need to change the javascript request url to '/api/chat/', or move the code to the handler you expected.

    Also, you are setting the model wrong in the handlers. It does not need a Meta nested class. It should be:

    class PostHandler(BaseHandler):
        model = Post
    
    class ChatHandler(BaseHandler):
        model = ChatMsg
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a class which routes messages to their handlers. This class
I have a Handler class that looks like this: class Handler{ public $group; public
I have this code : class Event{}; class CustomEvent:public Event{}; class Handler { public:
I have a form that handles editing of a domain model (A). This domain
I have this app.yaml file: application: ***** version: 1 runtime: python api_version: 1 handlers:
I have this problem with Slim framework . I have class Template that have
I have this basic utility class fetches (possibly) shortened URLs in parallel and returns
I have a server side code to process uploaded binary files: class UploadHandler(webapp.RequestHandler): def
I have the following model in MVC: public class IndexViewModel { public SubViewModel SubViewModel
I have this case where I'm creating 2 different event handlers placed in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.