django get POST data with a spaces inside
I need to get POST data with spaces in it.
I have folder with files in it. Files can have different names, so the problem when I am working with files which contains spaces in th开发者_如何学编程eir name, like "some long name with spaces.txt" This is html form, nothing special:
<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">
So while processing data from this form:
new_file = request.POST.getlist('file')
data processing, like moving, renaming and etc i am getting following error:
[Errno 2] No such file or directory: 'upload/some'
seems to me, it cuts everything after first word, how I can bypass this issue?
Thank in advance!
Surround your value field with quotes and you should be fine. (Just tested this)
<input type="checkbox" name="file" value={{ file }} />
should be
<input type="checkbox" name="file" value="{{ file }}" />
精彩评论