ユーザーがデータベース データの一部をエクスポートできるようにしようとしています。django-webodt を使用して、データから .odt ファイルを作成しています。次に、ダウンロードを許可しようとしています。ファイルは正常に作成されますが、ダウンロードすると空のファイルがダウンロードされるようです。サーバーがファイルを探している場所と実際の場所には違いがあると思います。これを適切に機能させる方法を考えていましたか?私はdjangoに比較的慣れていないので、助けていただければ幸いです。私が持っているコードは以下の通りです:
def downloadBook(request, val):
template = webodt.ODFTemplate('conversion.odt')
context = dict(ideas=Book.objects.getIdeaSet(int(val)))
document = template.render(Context(context))
file_name = os.path.basename(document.name)
path_to_file = os.path.dirname(document.name)
response = HttpResponse(mimetype='application/force-download')
response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(file_name)
response['X-Sendfile'] = smart_str(path_to_file)
return response