从
HTML:
<form enctype="multipart/form-data" action="/convert_upl" method="post">
Name: <input type="text" name="file_name">
File: <input type="file" name="subs_file">
<input type="submit" value="Send">
</form>
Python(Google App Engine):
if self.request.get('file_name'):
file_name = self.request.get('file_name')
我的问题是我没有从 file_name 文本输入中收到任何数据。我知道问题是因为它存在于 enctype="multipart/form-data" 形式中,但我不知道如何解决它 - 我的意思是如何一键从输入接收文件和字符串的提交按钮。
提前致谢。
HTML:
<form enctype="multipart/form-data" action="/convert_upl" method="post">
Name: <input type="text" name="file_name">
File: <input type="file" name="subs_file">
<input type="submit" value="Send">
</form>
Python (Google App Engine):
if self.request.get('file_name'):
file_name = self.request.get('file_name')
My problem is that I receive no data from file_name text input. I am aware that the trouble is because of it's existence within the form enctype="multipart/form-data" but I don't know how to solve it - I mean how to receive a file and the string from the input with one click of the submit button.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
上传示例代码对我来说效果很好。您是否尝试过确切地使用该代码?它对您有用吗?或者您发现了什么问题?
正如您将看到的,该示例的表单与您正在使用的编码相同:
只是在 HTML 中更加小心地正确使用
label
标记来显示字段标签,但这只会影响表单在浏览器中呈现时的外观。Python 代码也与您所显示的类似(对于您所显示的小型 susbset):
当然,
/sign
URL 定向到其do_post
方法的类我们刚刚展示了。那么,如果这段代码可以工作而你的代码不能工作,那么区别在哪里呢?不在您向我们展示的部分中,所以它一定在您尚未展示的某些部分中...您可以从 Google 复制此示例代码的部分吗?工作正常吗?
The uploading example code works fine for me. Have you tried using that code exactly? Does it work for you, or what problems do you see?
As you'll see, that example has a form with the same encoding you're using:
it's just a bit more careful in the HTML to properly use
label
tags to display field labels, but that only affect the form's looks when rendered in the browser.The Python code is also similar to what you show (for the tiny susbset that you do show):
and of course the
/sign
URL is directed to the class whosedo_post
method we've just shown.So, if this code works and yours doesn't, where is the difference? Not in the part you've shown us, so it must be in some parts you haven't shown... can you reproduce the part about this example code from Google working just fine?
您正在使用 POST 方法发送数据,但随后尝试使用 GET 方法获取数据。
而不是
做类似的事情
You are using the POST method to send the data but then are trying to get it with the GET method.
instead of
do something like