0

我有一个表单,它有几个复选框和文本框,它们的值都由一个提交按钮传递到不同的 url。但是,我现在正在尝试编写新的 url 页面,但不知道如何访问这些值。

<form name="myform" action="result" method = "get">

        <fieldset>
            <input type="checkbox" value="total_money" name="check" onchange="javascript:toggle('money');" /> Filter by Total Money</br>

                <div id="money" style="display:none" name="option">  

                    <input type="checkbox" value="more" onchange="javascript:toggleLine('money_text');"  name="condition"/> <label for="condition" > > </label>

                        <div id = "money_text" style="display:none"  >
                            <input type="text" id="money_box" name="money_name" value="lower limit" />
                        </div></br>

                    <input type="checkbox" value="less" onClick="javascript:toggleLine('money_text1');" name="condition"/> <label for="condition1"> < </label>

                        <div id = "money_text1" style="display:none;"  >
                            <input type="text" id="money_box1" name="money_name1" value="upper limit" />
                        </div>

                </div>

            <input type="checkbox" value="employees" name="check" onchange="javascript:toggle( 'employees');"/> Filter by Employees</br>

                <div id="employees" style="display:none" name="option"> 

                    <input type="checkbox" value="more" onchange="javascript:toggleLine('employees_text');" name="condition"/> <label for="condition" > > </label>

                        <div id = "employees_text" style="display:none"  >
                            <input type="text" id="employees_box" name="employees_name" value="lower limit" />
                        </div></br>

                    <input type="checkbox" value="less" onClick="javascript:toggleLine('employees_text1');" name="condition"/> <label for="condition1"> < </label>

                        <div id = "employees_text1" style="display:none;"  > 
                            <input type="text" id="employees_box1" name="employees_name1" value="upper limit" />
                        </div>
                </div>                         
        </fieldset>
    <input type="submit" value="Submit" />
</form>​

我得到的 url 响应看起来像这样(取决于检查或不检查的内容/输入):

url:   http://127.0.0.1:8000/crunchApp/result?check=total_money&condition=more&money_name=lower+limit&money_name1=upper+limit&check=employees&employees_name=lower+limit&condition=less&employees_name1=upper+limit

我需要将此标准用作搜索数据库但似乎无法弄清楚的python方法的参数。任何帮助将不胜感激!

4

2 回答 2

0

这可以通过一点搜索找到。

http://www.daniweb.com/software-development/python/threads/22312/get-posted-form-data-in-python

python cgi script--->addDo.cgi

import cgitb; cgitb.enable()
import cgi
import sys
form = cgi.FieldStorage()

// THIS IS WHERE THE VARIABLE IS READ FROM THE HTTP FORM POST
photos = form["photolist"]

i=0
for photo in photos:
    i = i + 1
    finalPhoto = finalPhoto + "," + photo[i]
于 2012-08-24T00:16:18.623 回答
0

如果你想使用类似的东西,你可以很容易地在瓶子里做到这一点:

from bottle import route,request,static_file,template

@route('/mypage',method="GET")
def get_mypage():
    #return static_file('mypagetopost.html')  #you can use either static_file or template
    return template('mypagetopost.tpl')
@route('/mypage',method="POST")
def post_mypage():
    money_text=request.forms.get("money_text")  #you get the value of the form by getting it by name.
    #return "Your money_text text was:%s" % money_text
    return template('yourposttemplate.tpl',yourpostpagevarformoney_text=money_text) #you can pass variables to your template through returning the template, however you cannot do this with static_file

需要在您的 html 页面中进行调整:添加:action="/mypage" method="post"到您的提交中。

另请注意,在默认情况下使用带有 Bottle 的 WSGI 服务器时,您需要设置静态文件处理程序(用于 css/js/static html)并相应地更改您的链接。

于 2012-08-24T19:43:41.723 回答