我正在训练在 Django 中下载文件。我找到了很多方法来做到这一点,没有人适合我。有谁能够帮我?这是我在views.py中的实际代码:
if form.is_valid():
format = form.cleaned_data['format']
x.saveCalculatedRoute( tempRoute+request.user.username, format )
path_to_file = '/var/www/tottrack/media/zones/temp/marc.osm'
response = HttpResponse(mimetype='application/force-download')
response['Content-Disposition'] = 'attachment; filename=prova.osm'
response['X-Sendfile'] = smart_str(path_to_file)
return response
它下载一个空文件,我该如何填写?坦克!!