【问题标题】:Sending form data in HTML with Python and Google App Engine使用 Python 和 Google App Engine 以 HTML 格式发送表单数据
【发布时间】:2013-09-14 22:23:24
【问题描述】:

我的 HTML 代码:

<form action="/set_image" method="post" id="form1" runat="server" enctype='multipart/form-data'>
       <div class="fileButtons">
       <input type='file' id="imgInp" name="imgInp" accept="image/*"/>
        <input type="submit" id="submit" name="action" value="Send"/>
        <input type='button' id='remove' value='Remove' />
        </div>
    </form>

main.py:

class SetImage(webapp2.RequestHandler):
    def post(self):
        id = str(self.request.get('id'))
        image = str(self.request.get('imgInp'))
        if (image):
            set_image(id, image)
            self.response.out.write("Image Uploaded")
        else:
            self.response.out.write("No Image Selected")

我可以得到图像,但是当我尝试打印它时,id 是空的。

【问题讨论】:

    标签: python html webapp2


    【解决方案1】:

    如果您希望获得名称为 id 的 post 值,则需要在表单中的某个位置将其作为表单元素。如:

    <input type="text" name="id" />
    

    但是,我不建议使用 id 作为表单元素的名称,因为它可能会导致名称冲突。

    如果您尝试获取文件的名称,则该值可能存储在:

    id = self.request.POST.get('imgInp')
    

    【讨论】:

      猜你喜欢
      • 2012-04-30
      • 2011-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多