您的位置:首页 > 编程语言 > Go语言

Django - 上传文件(初稿)

2009-11-02 18:41 363 查看
views:

from django.shortcuts import render_to_response
error = False
def upload_file(request):
if request.method == 'POST':
try:
file = request.FILES['file']
except KeyError:
return render_to_response('upload.html', {'error': True})
d1 = open("/path/tmp01.xls", 'wb+')
for chunk in file.chunks():
d1.write(chunk)
d1.close()
return render_to_response('upload.html', {'up': 1})


template:

#############################3

<html>

<head>

<title>Upload File</title>

</head>

<body>

{% if error %}

<p style="color: red;">

There are something error.

</p>

{% endif %}

{% if up %}

<p>Welcome to UPLOAD FILE SYSTEM.</p>

{% endif %}

<form enctype="multipart/form-data" action="" method="post">

upload file: <input type="file" name="file" maxlength=100 />

  

<input type="submit" value="Upload" />

</form>

</body>

</html>

##############################
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: