使用post函数通过python的html textarea [英] html textarea via python using post function

查看:268
本文介绍了使用post函数通过python的html textarea的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        <div><textarea cols="25" rows="12" name="box" id="box" tabindex="2">TEXT GOES HERE </textarea>

     </div>

    <div>
    <p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="Submi" tabindex="2"  /></p>      </div>
</form>

如何使用post函数用python代码中的文本填充文本区域? 我一直在尝试这种方式,但它行不通! :S br = {'box':"NEW text"}

解决方案

我假设表单显示在页面上的python代码块中,在这种情况下,您可以使用字符串格式操作(python 2.6或更高版本)来在所需位置添加值:

print """
<div><textarea cols="25" rows="12" name="box" id="box" tabindex="2">{0!s} </textarea>""".format( text_variable )

某些虚拟主机仍使用python 2.5,在这种情况下,您将需要使用较旧的语法样式:

print """ My text says: %s """ % text_variable

如果要执行此操作以显示任意用户输入,请确保以某种方式对字符串进行预处理,以避免在表单中间插入任意HTML代码.

为了设置* text_variable *,您需要获取表单数据.查看python"cgi"模块和相关的教程.. >

        <div><textarea cols="25" rows="12" name="box" id="box" tabindex="2">TEXT GOES HERE </textarea>

     </div>

    <div>
    <p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="Submi" tabindex="2"  /></p>      </div>
</form>

How can I fill the text area with my text from python code using post function? I've been trying this way, but it just wont work! :S br = { 'box' : "NEW text"}

解决方案

I assume that the form is displayed in a block of python code on the page, in which case you could use string formatting operations (python 2.6 or newer) to add in the value at the desired location:

print """
<div><textarea cols="25" rows="12" name="box" id="box" tabindex="2">{0!s} </textarea>""".format( text_variable )

Some web hosts still use python 2.5, in which case you'll need to use an older syntax style:

print """ My text says: %s """ % text_variable

If you are doing this to display arbitrary user input, be sure to pre-process your string in some way to avoid the insertion of arbitrary HTML code in the middle of your form.

In order to set *text_variable*, you'll want to get the form data. Look at the python "cgi" module and relevant tutorials.

这篇关于使用post函数通过python的html textarea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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