Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tornado URL and HTML form

I'm using tornado and I want to Insert something to my MongoDB from values in a HTML form.

in the HTML file I have a form like this:

<form method="get" > 

with 2 textbox and a submit button. and I don't know what to set as "action"

I have a handler class with a function called "post" like bellow:

 class MyHandler(tornado.web.RequestHandler):
  def post(self):
     name  = self.get_argument("Name", "")
     index = self.get_argument("Index","")
      .... code for updating MongoDB

I have a file called BaseUrl.py that contains:

(/admin/edit[/]?',MyHandler  )

but it seems that the "post" function in myHandler does not execute. could you please give me some advice about how to properly set my URLs and form actions?

like image 777
Adel Avatar asked Dec 05 '25 15:12

Adel


2 Answers

Change the form method to POST as you are handling in a POST request:

<form method="POST" >

You also need to provide an action if the form is served from different page, so your form should be:

<form method="POST" action="/admin/edit">
like image 56
avi Avatar answered Dec 07 '25 05:12

avi


Your post method isn't called because your form specifies method="get". Change that to method="post" and it'll probably work.

If the action is empty the browser will submit the request to the current page, so if you have a get handler serving the form at the same URL you don't need to specify it.

like image 21
thusoy Avatar answered Dec 07 '25 05:12

thusoy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!