diff --git a/mezzanine/forms/admin.py b/mezzanine/forms/admin.py index dc5d8a93c0..7fb12a054d 100644 --- a/mezzanine/forms/admin.py +++ b/mezzanine/forms/admin.py @@ -169,10 +169,10 @@ def file_view(self, request, field_entry_id): field_entry = get_object_or_404(FieldEntry, id=field_entry_id) path = join(fs.location, field_entry.value) response = HttpResponse(content_type=guess_type(path)[0]) - f = open(path, "r+b") - response["Content-Disposition"] = "attachment; filename=%s" % f.name - response.write(f.read()) - f.close() + with open(path, "r+b") as f: + response["Content-Disposition"] = ("attachment; filename=%s" + % f.name) + response.write(f.read()) return response admin.site.register(Form, FormAdmin)