我需要获取其中包含空格的 POST 数据。
我有一个包含文件的文件夹。文件可以有不同的名称,所以当我处理名称中包含空格的文件时出现问题,例如“一些带有空格的长名称.txt”这是html形式,没什么特别的:
<form action="" method=post>
{{ form }}
<table border="1">
<tr><td>File Name</td><td>upload</td></tr>
{% for file in file_list %}
<tr>
<td>{{ file }}</td>
<td><input type="checkbox" name="file" value={{ file }} /> <br /></td>
</tr>
{% endfor %}
</table>
<input name="" type="submit" value="Sent">
Run Code Online (Sandbox Code Playgroud)
因此,在处理此表单中的数据时:
new_file = request.POST.getlist('file')
Run Code Online (Sandbox Code Playgroud)
数据处理,如移动、重命名等我收到以下错误:
[Errno 2] No such file or directory: 'upload/some'
Run Code Online (Sandbox Code Playgroud)
在我看来,它会在第一个单词之后切断所有内容,我如何才能绕过这个问题?
预先感谢!
用引号包围你的值字段,你应该没问题。(刚刚测试过这个)
<input type="checkbox" name="file" value={{ file }} />
应该
<input type="checkbox" name="file" value="{{ file }}" />
| 归档时间: |
|
| 查看次数: |
1137 次 |
| 最近记录: |