html textarea via python using post function

旧时模样 提交于 2019-12-13 11:23:00

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/10808852/html-textarea-via-python-using-post-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!