如何使用flask设置输入文本的值?

时间:2018-04-25 17:22:24

标签: python flask

我使用python 2.7,并且当我点击某个按钮,使用flask时,我想在HTML中为输入文本字段设置值。 这该怎么做 ?

def submit_textarea():
    text = request.form.get("text")
    outfile = codecs.open('output.txt', 'w', 'utf-8')
    outfile.write(text)

    return render_template("index.html") 

此函数获取文本并将其发送到文本文件我想为其他输入文本字段设置一些文本。

1 个答案:

答案 0 :(得分:-1)

我不完全确定我是否理解你的问题,但我认为这就是你要做的......

U-Boot SPL 2016.01-00763-g3faf221 (Jan 29 2016 - 20:47:08) Trying to boot from MMC Card doesn't support part_switch MMC partition switch failed *** Warning - MMC partition switch failed, using default environment reading u-boot.img reading u-boot.img U-Boot 2016.01-00763-g3faf221 (Jan 29 2016 - 20:47:08 +0000) Watchdog enabled I2C: ready DRAM: 512 MiB MMC: OMAP SD/MMC: 0, OMAP SD/MMC: 1 *** Warning - bad CRC, using default environment Net: <ethaddr> not set. Validating first E-fuse MAC cpsw, usb_ether Press SPACE to abort autoboot in 2 seconds => set sdboot 1 => boot switch to partitions #0, OK mmc0 is current device Scanning mmc 0:1... switch to partitions #0, OK mmc0 is current device SD/MMC found on device 0 reading boot.scr ** Unable to read file boot.scr ** reading uEnv.txt 235 bytes read in 5 ms (45.9 KiB/s) Loaded environment from uEnv.txt Importing environment from mmc ... Running uenvcmd ... reading uImage 5497536 bytes read in 302 ms (17.4 MiB/s) reading /am335x-boneblack.dtb 25926 bytes read in 8 ms (3.1 MiB/s) ## Booting kernel from Legacy Image at 82000000 ... Image Name: Linux kernel Created: 2015-09-07 21:47:16 UTC Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 5497472 Bytes = 5.2 MiB Load Address: 80008000 Entry Point: 80008000 Verifying Checksum ... OK ## Flattened Device Tree blob at 81ff0000 Booting using the fdt blob at 0x81ff0000 Loading Kernel Image ... OK Loading Device Tree to 8fff6000, end 8ffff545 ... OK Starting kernel ... Uncompressing Linux... done, booting the kernel. [ 0.177572] omap2_mbox_probe: platform not supported [ 0.333923] tps65217-bl tps65217-bl: no platform data provided [ 0.397544] bone-capemgr bone_capemgr.9: slot #0: No cape found [ 0.434652] bone-capemgr bone_capemgr.9: slot #1: No cape found [ 0.471760] bone-capemgr bone_capemgr.9: slot #2: No cape found [ 0.508869] bone-capemgr bone_capemgr.9: slot #3: No cape found [ 0.528815] omap_hsmmc mmc.5: of_parse_phandle_with_args of 'reset' failed [ 0.591166] pinctrl-single 44e10800.pinmux: pin 44e10854 already requested by 44e10800.pinmux; cannot claim for gpio-leds.8 [ 0.602845] pinctrl-single 44e10800.pinmux: pin-21 (gpio-leds.8) status -22 [ 0.610128] pinctrl-single 44e10800.pinmux: could not request pin 21 on device pinctrl-single [ 0.686675] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) [ 0.695344] [<c0010f5d>] (unwind_backtrace+0x1/0x98) from [<c04994c3>] (panic+0x5b/0x158) [ 0.703882] [<c04994c3>] (panic+0x5b/0x158) from [<c07bc94b>] (mount_block_root+0xf7/0x178) [ 0.712595] [<c07bc94b>] (mount_block_root+0xf7/0x178) from [<c07bcb09>] (mount_root+0x95/0xb0) [ 0.721676] [<c07bcb09>] (mount_root+0x95/0xb0) from [<c07bcbef>] (prepare_namespace+0xcb/0x11c) [ 0.730836] [<c07bcbef>] (prepare_namespace+0xcb/0x11c) from [<c0495aff>] (kernel_init+0x7/0x98) [ 0.740007] [<c0495aff>] (kernel_init+0x7/0x98) from [<c000c7fd>] (ret_from_fork+0x11/0x34)

index.html

如您所见,文本字段的名称为<form action="/get-text" method="POST"> <input type="text" name="first_name"> <input type="submit" value="Go"> </form>

first_name

app.py

当您在变量@app.route('/get-text', methods=['GET', 'POST']) def foo(): bar = request.form['first_name'] 中按GO时,此示例将存储键入文本输入的内容。