龙卷风URL和HTML表单 [英] tornado URL and HTML form

查看:92
本文介绍了龙卷风URL和HTML表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用龙卷风,我想从HTML表单的值中插入一些东西到我的MongoDB中。

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

在HTML文件中我有一个这样的表单:

in the HTML file I have a form like this:

<form method="get" > 

带有2个文本框和一个提交按钮。
,我不知道该怎么设置为action

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

我有一个名为post的函数的处理程序类,如下所示:

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

我有一个名为BaseUrl.py的文件,其中包含:

I have a file called BaseUrl.py that contains:

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

但似乎是post 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?

推荐答案

更改表单方法来POST,就像您在POST请求中处理一样:

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">

这篇关于龙卷风URL和HTML表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆