Tornado message method not found

I am trying to publish a form on the Tornado web server, but whenever I click the submit button, the following error generates

405 Method Not Allowed

Here is the form

 <form method="post"> First name: <input type="text" name="fname"><br> Last name: <input type="text" name="lname"><br> <input type="submit" value="Submit"> </form> 

I tried to change the "get" method on the main request handler to a "post", but it does not work. The only method that works is GET,

 class MainHandler(BaseHandler): """ Main request handler for the root path and for chat rooms. """ @tornado.web.asynchronous def get(self, room=None): 

Any suggestions?

+3
source share
3 answers

After this long chat window, I realized that the best way for you is to transfer data through cookies.

Here is a tutorial: http://www.w3schools.com/js/js_cookies.asp

An alternative resource is breaking your data into several parts.

One approach is to query the endpoint that gives you a unique identifier. Then send a series of requests in the form ?id=XXX&page=1&data=... before closing it with ?id=XXX&total_pages=27 , after which you collect different fragments on the server.

+1
source

The only method that works is GET , because the only method you defined in a subclass of your handler is get() . To handle POST define the post() method instead of (or in addition to) get() .

+3
source

I downloaded the sample project and started it myself. I think I have made some progress.

Firstly, the original MainHandler is not able to handle the POST request. According to the code, it processes a request like /room/1 , /room/2 .

Secondly, I think that you are trying to simulate a login form. However, the GET method and /login as the endpoint are used in the login form:

 <form class="form-inline" action="/login" method="get"> 

I assume that you will also put your form in index.html, whose URL is actually /login (if not logged in) or /room/X (logged in). Thus, you probably end up in LoginHandler.

Third, when I add a mail method to MainHandler and send a POST request to /room/1 , it actually works and triggers a 500 Internal Error.

I use curl to check out a few cases. If you try to send a POST request to MainHandler to / , it doesn't even respond! Because, as mentioned earlier, get is defined as get (self, room = None). It accepts only /room/X

If you try it on /room or /login , the answer will be 405 Method Not Allowed .

If you want POST to be available for /login , the easiest way is to add POST to LoginHandler as follows:

 @tornado.web.asynchronous def post(self): self.get() # or this post = get 
+3
source

Source: https://habr.com/ru/post/1211823/


All Articles